Dealing with IE "Operation Aborted". Or, how to Crash IE

It's easy to create runtime errors in JavaScript. But it's not every day you find a way to crash the runtime entirely.

It looks so innocent, yet it is so delightfully evil... copy/paste this into a simple HTML file and open it.

<html>
<head>
    <script type="text/javascript">
    function appendToBody() {
        var span = document.createElement('span');
        document.body.appendChild(span);        
    }
    </script>
</head>
<body>
    <form>
        <script type="text/javascript">
            appendToBody();
        </script>
    </form>
</body>
</html>

This is what you see:


For the search engines: "Internet Explorer cannot open the Internet site", "Operation aborted" :)

Upon clicking the one and only thing you can click on, your page is completely replaced with this...


"The page cannot be displayed"

Unfortunately the error isn't very helpful, so if you run into this you will likely scratch your head searching for an answer. You'll probably find suggestions like "reinstall IE" or "use Firefox". Don't listen to that nonsense :)

The problem is you can't append to the BODY element from script that isn't a direct child to the BODY element.

If you research it enough, you will find that some people ran into this when they had script inside a <table>. The proposed fix was to move the script outside the <table> element. But that would only work if the <table> was a direct child to the body! If the table is inside yet another element, it will still fail.

And of course, it's ok if your script isn't a direct child of BODY as long as it doesn't execute inline while the page is being parsed. So for our example here, you could fix it by moving the script to the top or bottom of the body, moving it after the body, or putting it in a function and calling it from window.onload or in response to some other event.

With AJAX apps becoming ever more popular, DOM manipulation is becoming more commonplace, and I fear more and more people may run into this. Hopefully this helps.

70 Comments

  • Is there a good reason to execute script in an HTML body instead of in the HTML HEAD? &nbsp;This error seems like a great reason not to.

  • I'm afraid for this specific example that won't work -- the body hasn't been parsed yet by the browser when you're still in the head element. So, "document.body" will be null. Now, having that same script hookup to window.onload and manipulate the body in the handler, that would work. There are times where you need to do things before window.onload though.

    I don't want this to turn into a sequence of comments about best practices -- the point of the article is to help people figure out what is causing the error, nothing more. Avoiding the error in the first place is an entirely different topic :)

  • it&#39;s a pity that IE does not handle this situation better. I#ve seen commerical enterprise applications that routinely spit out this message. &nbsp;

  • frb -- waiting for window.onload is a safe bet. However there are times when that is not good enough. The DOM itself is ready for manipulation before window.onload, because window.onload waits for all binary content to also be downloaded. Imagine you have some huge picture to download or sound file -- the page will sit there, ready for manipulation while it downloads. So certainly sometimes window.onload isn't soon enough.

    Some browsers have a non standard event that states the dom is ready (IE does not, but putting code at the bottom of the body or using a script defer tag are just some of the tricks you can use to simulate one).

  • Thanks hommie, this really helped!

  • Great help, really saved my butt!
    Thanks!

  • Is there a good reason to execute script in an HTML body instead of in the HTML HEAD? This error seems like a great reason not to.

    Well, in my appplication I wanted to display a message about page being loaded right at the beginning. Obviously I can't wait for the load event with this (that is supposed to hide the message), nor can I move the stuff the because the script is a part of a template, which doesn't have head section (it's included by the templating framework somwhere else). Had to turn this off for all MSIE users. (this bug is present in IE7 as well)

  • richard -- if you have inline script that needs to insert dom elements, you can do it with document.write(). You can use appendChild as well, just as long as its to an element that is previous and already closed. No need to disable it for all of IE... just avoid appending to an incomplete element, pretty simple.

  • Defer delays the execution of the script in IE, but not other browsers. So you could end up with different behavior if you use it. Its a quick fix if it fits your scenario, but consider better solutions.

  • i need to touch with u ... i like it ...this site is very use ful for me ...

    i m .net Employee , i m working in india

  • That error was smashing me in the teeth. Thanks for the post! Great job...

  • Thanks a lot for sharing this information

  • The described crash can be caused by CSS expressions.

    Here's the example of implementing round corner block:

    .xreview { background: #e0e9fd; padding: 8px 20px 20px 20px; margin: 0 6px 20px 15px; font-family: Georgia, "Times New Roman", Times, serif; color: #303030; font-size: 12px;}

    /* Mozilla additions work perfectly */
    .xreview:before { content: url(/img/xreview_top_left.gif); background: url(/img/xreview_top_right.gif) no-repeat 100% 0; height: 20px; display: block; margin: -8px -20px -8px -20px; }
    .xreview:after { content: url(/img/xreview_bottom_left.gif); background: url(/img/xreview_bottom_right.gif) no-repeat 100% 0; height: 20px; display: block; margin: -8px -20px -24px -20px; }

    /* IE6 addition which crashes occasionally */
    .xreview { zoom:1; behavior:expression(!this.isInserted==true ? this.isInserted=(this.innerHTML = '' + this.innerHTML + '') : ''); }

    Note that IE won't crash every time and that makes bug more difficult to catch.

  • how do you mfix this i don't understand

  • dude u saved our a$$.. thanks...

  • setTimeout is ok for me.

  • "window.onload = appendToBody;" work perfect, thx!

  • Thanks, it saved me too. I was loadnig all my custom javascipt dropdown boxes with dropdowns that get added outside of the content area, but the script was running inside a DIV tag. It worked in FireFox and I mostly develop in Linux FireFox, so I didn't notice it until I tried to access the site in IE. Thanks to you it works again!

  • This happens with Overlib.js, so I think I must change this library...

  • Could you please check my website motls.blogspot.com to see whether it is the same error? Similar window has been appearing to me and people with IE6 and IE7 complain sometimes.

    If you also write me an easy innocent fix, it will be appreciated. Lubos dot Motl at Gmail dot com.

  • Lubos -- I don't get the error. I notice though that your page takes a pretty long time to load, and it seems to be due to the large number of 'widgets' you have on the right column. Its likely one of those causing the error, they are certainly causing slowness.

  • I've got this error, I used something like $(object).innerHTML = '...' that caused IE crashed.

    to fix this (I was using mootools), I had to use domready event.

    window.addevent('domready', function () {$(object).innerHTML = '...'; }) and there were no more crashed.

    - regards

  • thanks man its work successfully..

  • Hi,
    I've had the 'operation aborted' come up when i try to open my gmail account. I'm not really computer savvy and don't understand all the jargon that is in the above comments. Is there an easy step by step option to crash IE for an everyday person like me?
    Thanks

  • On IE, i get the Operation Aborted Error. Can someone help me here? Please.

    Thanks.

  • I dont; think so that is based on javascripts.
    I have same problem on 2 computers but on 10 another on same configuration (XP, IE6) works fine.
    one of 2 problematic compuer was freshly reinstaled, without any installed service pack or any upgrades. WHY this 2 stupid compuers make me crazy? It mostly crashed on my web applications where i used wrapped variables technology (quick redirect on the same page and hide all posted values of variables)

  • Thanks for this. Likely saved me a day of head scratching.

  • Thank you for writing this article! &nbsp;This is exactly the answer I was looking for!

  • hi,
    I am having the same problem. There were script between tag , we removed that. But problem is still that. We are using Menu. Wherever click on menu item. page redirect to next page but still operation Aborted Msg comes. and page lost. We are calling javascript function in body tag. Does it make any different?
    Your answer is awaited...

    Thanks

  • Gaurang -- are you sure the error isnt actually coming from the page you are linking to? Theres really no possible way I could help you other than toss ideas at you, without seeing code.

  • Thanks for this. Pages with Google maps tags started playing up - and you've saved me a lot of head scratching.

  • Could someone give me the answer in a novice user's terms? Sorry

  • Michael -- are you a user of the site or a developer of it? You'd have to be a developer of it to fix it. Many people find this blog entry as end users who get this from various sites, but the problem lies with the site's code.. not with the users machine.

  • Interesting topic. As InfinitiesLoop said I found this blog because I am an end user and got this error message from a web site (Expedia). It happens on one computer but not another, so I figured it was the user's computer causing the problem.

    I'm still not sure why it's only happening on one computer, but I'll stop looking on my end.

  • Thx a lot for solution.

  • Can you tell us web users (not developers) how we can get around this? I get this error just opening Google and want to be able to use Google with IE and not only Firefox.

  • MrT -- there isnt anything an end user can do except keep trying, sometimes the error is intermittent. You could also try complaining to the site owner through whatever feedback mechanism they have in place. I'm sure google has something like that, but not sure...

  • I have a webpage that is having this problem (only on one page) (please click the children book illustration navigation button. All the other pages work except this one - however, this page does have a simple veiwer slideshow feature within it. Any help would be grwat.

    www.designhousestudios.co.uk

  • I am the developer of the site. Works perfect in FF. Am using a js for rotating images from dynamic drive for the frontpage. I keep getting this message whenevr i try to refresh the page. I am using Drupal open source to create the site and hence will not be able to prevent having the js in the body of the page. Is there any other way i can resolve this. Am really in a fix and would greatly appreciate any help. thanks in advance.

  • Hi , I have a same problem but my problem happends when I run a test with Waitj Framework (a extension for Junit to Web automated test) , this page has no problem for anybody but and before I never have Problem.. so this very weird , I need know if someboby has or had this problem.
    I use a IE 7 and XP OS.
    PLEASE HELP ME!!

  • Thanks this is a great post and really help me to solve the issue on IE6+7.

  • this is a really great tip I've never seen anywhere else. I've ran into this problem so many times, especially appending a table in a table

  • I have this same problem "Operation Aborted". this only occurs when I change a filter value in the report. I have tried everyothing. Can someone please help

  • Nice entry. Pointed me in the right direction to trace the Javascript that caused the "Operation aborted" error on IE. :)

  • If you are still having issues, we had this problem and were using classic asp and solved it by using a 'If' statement.

  • This problem doesn't always happen as described in the Microsoft's KB or here. What I found so far is that it's related to Javascript but not necessary to DOM manipulations. In some cases simply accessing an element may cause this error, that's probably some deeper bug than it appears to be.

  • This is something that is killing me! I don't how to fix this. if you go to my site. www.fineoperaglasses.com and click on any product it will give me this error message... anyone know what is going on in my site?

  • So how does this help a person browsing a website? It's annoying to be at a site used by 100's of 1000's of people per day and it pop up everytime you click a link.

  • It doesn't help you if you're just a user of the site, but you could forward this to the site's webmaster and they can fix it :)

  • Pls advice to fix operation aborted error when using IE 7.0

  • Now I am really confused re: IE and 'abort operation'. I'no techy tahts for sure but hwo can there be 3 or 4 different HTML codes to use. don't know where to begin and don't want to fool around with it because I'm a rooky. The only thing I did differently was to add plugin (onlywire.com) and then added a child page to a prent page, which acutally doesn't show up anyway. Thanks in advance for any help. Funny my web server people said the site came up no problem. Susan

  • Can I add further to my comment made a an hour or so ago...I wa able to bring the site up in FF okay but in in IE. thanks Susan

  • I have tried deleting posts and content and still with IE get an 'abort message' I am able to access with FF and the blog is set up with FF, but those who visit through IE cannot access since my last post.

    Please help me????? :(

  • The defer method worked best for me.
    Just use it on your inline javascript as needed.

  • Filip -- setTimeout does not return a function that you call, it returns a token that you can use to clearTimeout. So it seems your code is only working because your setTimeout calls the init function after 200ms, not because it's part of the onload event. What does the code that supposively does not work look like? If you're doing this:

    document.body.onload = init_ajax_menu();

    Then its not going to work because you aren't assigning the function to call during onload, you're calling the function, and assigning its return value to onload.

  • Thanks, this was very helpful ... it works now

  • ureka!

    Thx man this really helped solve my problem.

    i wonder how ms couldn't fix this bug since 2006.

  • Well, I have the same problem with my blog. However, I am not sure which fragment of javascript causes this error. Could be caused by scripts that are added by third party ads or the blogging engine. I'm totally confused :(

  • very helpful, thanks very much.

  • What is a simple HTML file and how do you copy and paste that message to it!

  • Saved my life, sir. Thank you.

  • Hey I got my issue sorted. It makes it so much harder to fix stuff like this when you are using a builder that doesn't let you edit the template coding.

    The problem was a java script countdown that was running rampant on my site. As soon as I deleted it, the problem just went away.

  • But my website doent even use a javascript! Gr!

  • Is there any chance this is related to number of users? We've had an application (Javascript, IE 6) in development and test for several weeks, it went live, which meant 500+ new users, and then this error started occuring frequently.

    Could it also be related to an environment update? Its a corporate environment (users have no or very little control over their PCs) and am also thinking it could be some update that affected Internet Explorer security, particularly in running JavaScript.

  • Colm --- depending on what is causing it, but it is possible that it is a timing issue due to calls to setTimeout, etc. In that case it might be that users with slower connections, or if the site responds slowly due to load, would be more likely to hit the issue.

  • Thank you so much! I was going crazy until I found your post

  • To a website developer, your comments were undoubtedly very useful, however, what is a lame user like me to do? I keep getting this error on a number of websites. I feel it also has something to do with my IE settings.

  • Thank you.

    You saved me hours of head-aching work.

    Stupid IE6 :)

  • while accessing my blog in IE 8 I am also getting the same error. I am also using append child element...

  • Thanks. Solved my problem. Even though the script was "defer", I still had the problem. Fixed by moving to runtime.

Comments have been disabled for this content.