Internet Explorer : ”Operation aborted” Solution
If you ever worked with heavy JS codes or complex DHTML you may have already faced this error. This is like a nightmare. You are opening your web page. IE is loading the site. You see the progress bar. Suddenly you see a message “Internet Explorer cannot open the Internet site http://<Web site>.com. Operation aborted”. The dialog has only one button. so you press it. Then it shows “Page cannot be displayed”. You cannot even debug it. Cause you don’t see any source code. I searched many sites and forums. No one can say anything appropriately. See the MSDN site. They have some tips to avoid it. I don’t know how to reproduce it. But I’ll tell you a solution that worked for me. This solution works for me for jQuery javascript library.
In jQuery most initial operations are writen in domready block. That is,
jQuery(document).ready(
function(){
my_blah_blah_code();
}
);
The function there my_blah_blah_code() runs when DOM is ready. It means when all the elements is loaded in browser and its safe to manipulate it .
But I have seen its really not safe to manipulate it if we use the function jQuery(document).ready() block. You’ll say “No, its working for me”. Well then your lucky that its working. DOM also gives you a attribute in ‘body’ element. The ‘onload’ attribute. It always works. I never see it fails. Both ‘jQuery(document).ready()’ and ‘onload’ attribute gives the same functionality. But they are not same. To test it run a code like the following.
&lt;script src="/path/to/jquery" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
jQuery(document).ready(
function(){
alert("jQuery domready fires");
}
);
&lt;/script&gt;
You’ll see which alerts later. Its the browser. See the live example here. So its safer to use ‘onload’. Thats why I am using here only ‘onload’. No jQuery(document).ready() block. I am replacing the jQuery ready block by this,
<html>
<head>
<script type="text/javascript" src="/path/to/jquery"></script>
<script type="text/javascript">
function by_blah_blah_code(){
// Write all your initialization code here.
}
</script>
<body>
<script type ="text/javascript" >
if(document.body){
if(document.all){
document.body.onload = by_blah_blah_code;
}else{
document.body.setAttribute("onload","by_blah_blah_code()");
}
}else{
alert("This code must be included after the body tag ;)");
}
</script>
</body>
</html>
If you use it that way. You wont see any “operation aborted” error.
Best of luck.
© 2008 by A K M Mokaddim
Tags: domready, IE, Internet explorer, Javascript, jquery, onload, setattribute
