Thursday, November 02, 2006 4:58 PM InfinitiesLoop

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.

Filed under: , ,

Comments

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

Thursday, November 02, 2006 9:25 PM by Joe Chung

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.

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

Friday, November 03, 2006 12:10 AM by InfinitiesLoop

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 :)

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

Friday, November 03, 2006 2:17 AM by Damien

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

# re: Dealing with IE &quot;Operation Aborted&quot;. Or, how to Crash IE

Friday, November 03, 2006 5:06 PM by frb

I try to run all my JS in the window.onload handler. That way I know the document is loaded completely, I can enforce order, and I never have to modify the HTML to change the code.

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

Friday, November 03, 2006 7:02 PM by InfinitiesLoop

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).

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

Monday, November 13, 2006 10:49 AM by James Alexander

Thanks hommie, this really helped!

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

Tuesday, December 05, 2006 12:32 AM by Patrick

Great help, really saved my butt!

Thanks!

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

Sunday, December 10, 2006 10:50 AM by micah

Thanks for your solution! It saved my blog!

And I've referenced your post to my blog post (in chinese):

http://micah.blogsome.com/2006/12/09/snap-preview-anywhere/

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

Tuesday, January 02, 2007 5:28 PM by richard

<quote>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.</quote>

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 <head> 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)

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

Tuesday, January 02, 2007 6:20 PM by InfinitiesLoop

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.

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

Wednesday, January 03, 2007 2:08 AM by InfinitiesLoop

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.

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

Friday, February 23, 2007 4:53 AM by vadivel

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

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

Wednesday, March 21, 2007 11:24 AM by Webman

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

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

Wednesday, March 28, 2007 7:03 AM by Graham

If, in the appendToBody function, you do

var el = document.createElement('input');

el.value = "hello";

document.body.appendChild(el);

instead of the span, then when the error message appears, the page looks fine (ie. there's an <input> element with "hello" written in it), but after OK-ing the error the page is replaced with the "this page cannot be displayed" stuff. Strange...

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

Sunday, April 15, 2007 3:16 PM by Sumit Mehrotra

Thanks a lot for sharing this information

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

Friday, July 13, 2007 8:02 AM by Pupinux

Thanks a lot for this brief but really clarifing explanation! It helps me a lot and I hope will do the same for many others!

Keep up the great work!

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

Wednesday, July 18, 2007 8:01 AM by Mlungisi

I started on the project few days back and i had to figure out the problem. it is suspected that it's somewhere in the code. I have searche for innerHTML and apendChild. They did everything on either external js and/or in head tag of html file.

I tested some solutions whereby if you are modifying body tag through child tag like appendChild or using innerHTML, the problem occurs. If you take the script direct to body tag or head tag, the error disappears. I have not seen any javascript outside head tag but only tag libs like <g: javascript>. This kind of take usually have one line of code.

I am really confused now.

# GSIY &#8230; Ruby-Rails Portal

Wednesday, September 05, 2007 12:02 PM by GSIY … Ruby-Rails Portal

Pingback from  GSIY &#8230; Ruby-Rails Portal

# Dan Moore! &raquo; IE 7 has a built in javascript debugger

Thursday, September 13, 2007 11:51 AM by Dan Moore! » IE 7 has a built in javascript debugger

Pingback from  Dan Moore! &raquo; IE 7 has a built in javascript debugger

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

Tuesday, November 20, 2007 1:21 AM by Martin Russell

InfinitiesLoop -- I have a javascript from aweber that inserts an opt-in form on a page ie inline. Will your solutions of "document.write(). You can use appendChild as well, " work for something like this...?

<script type="text/javascript" src="forms.aweber.com/.../script>

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

Friday, December 14, 2007 8:40 AM by Barak Levy

hello all

I build this site:

www.tween-id.com/.../index.shtml

in the "projects" section, under "selected projects" there are some galleries, they work fine in FF but in IE 6 or 7 it bring up this error -

Operation Aborted, and i don't know why...

you can download the site files here:

www.tween-id.com/.../pitzubarak.zip

THANK YOU !!!!!!!!

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

Thursday, December 27, 2007 12:41 PM by Paul Gusakov

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 = '<span style="background: url(/img/xreview_top_right.gif) no-repeat 100% 0;height: 20px;display: block;margin: -8px -20px -8px -20px;"><img src="/img/xreview_top_left.gif" alt="" /></span>' + this.innerHTML + '<span style="background: url(/img/xreview_bottom_right.gif) no-repeat 100% 0;height: 20px;display: block;margin:-8px -20px -24px -20px"><img src="/img/xreview_bottom_left.gif" alt="" /></span>') : ''); }

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

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

Friday, January 11, 2008 5:07 PM by Dan irwin

how do you mfix this i don't understand

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

Tuesday, January 29, 2008 11:43 PM by rad

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

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

Saturday, February 09, 2008 5:53 AM by Rene

i also encountered the same problem on my site (www.partybacolod.com) i have a facebox script and every time when the page is too large, the error "Operation Aborted" pop's up... because there is a script on the facebox that it execute once the page is loaded, what I did is, put a timeout, heres the script:

function load_facebox()

{

jQuery(document).ready(function()

{

 jQuery('a[@rel*=facebox]').facebox()

})

}

setTimeout("load_facebox()", 5000);

I set the timeout to 5 sec. and now my site is working fine. =)

heehe... hope it helps on your scripts....

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

Tuesday, February 12, 2008 3:04 AM by Atikorn

setTimeout is ok for me.

# links for 2008-02-21

Wednesday, February 20, 2008 7:19 PM by k-märkt

Infinities Loop: Dealing with IE "Operation Aborted". Or, how to Crash IE (tags: operation_aborted javascript dom internet_explorer ie bugg)...

# [JRA-14036] Dashboard containing Projects Portlet does not display in Internet Explorer if many (100+) projects and over slow network

Thursday, February 28, 2008 10:43 PM by JIRA: JIRA

I think this is strongly related to the use of JavaScript while the page is loading. These sites speak more about the IE problem weblogs.asp.net/.../Dealing-with-IE-_2600_quot_3B00_Operation-Aborted_2600_...

# JavaScript问题汇总

Saturday, March 22, 2008 7:14 PM by RicCC

1.Ajax调用被杀毒软件/防火墙阻挡

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

Monday, March 24, 2008 10:58 AM by Kluyg

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

# macsf.net | breadcrumb | geeky matters

Wednesday, March 26, 2008 8:51 PM by macsf.net | breadcrumb | geeky matters

Pingback from  macsf.net | breadcrumb | geeky matters

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

Thursday, March 27, 2008 9:35 PM by daflame

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!

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

Monday, April 28, 2008 10:47 AM by david

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

# BUG: Error message when you visit a Web page or interact with a Web application in Internet Explorer: &#8220;Operation aborted&#8221; | Andrea Lazzari's blog

Pingback from  BUG: Error message when you visit a Web page or interact with a Web application in Internet Explorer: &#8220;Operation aborted&#8221; | Andrea Lazzari's blog

# Explorer &raquo; BUG: Error message when you visit a Web page or interact with a &#8230;

Pingback from  Explorer &raquo; BUG: Error message when you visit a Web page or interact with a &#8230;

# Explorer &raquo; Explorer ?? BUG: Error message when you visit a Web page or interact&#8230;

Pingback from  Explorer &raquo; Explorer ?? BUG: Error message when you visit a Web page or interact&#8230;

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

Friday, May 09, 2008 7:00 AM by Lubos Motl

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.

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

Saturday, May 10, 2008 5:04 PM by InfinitiesLoop

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.

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

Tuesday, May 13, 2008 6:26 AM by tbela99

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

Leave a Comment

(required) 
(required) 
(optional)
(required)