Crashing IE Posted by: Jordan in ProgrammingJavaScript on
IE still has a lot of bugs and I thought most were fixed in IE 7. This one bug I discovered while working with CCIT. I needed to include a div tag in the body for the TipLayer (the TipLayer is hidden until activated). I used the same DOM method as described here: Include a JavaScript file from a JavaScript file.

Here is the code I used:

function insertDiv() {
var s = document.getElementsByTagName("body")[0];
var js = document.createElement("div");
js.setAttribute('id', 'TipLayer');
js.setAttribute('style', 'visibility:hidden;position:absolute;z-index:1000;top:-100' );
s.appendChild(js);
}


In FireFox this works fine. Internet Explorer 6 or 7 throws an error "Internet Explor cannot open the internet site http://blog.codecall.net/. Operation aborted":




Which leads to this page (Page Cannot be displayed):



The problem is that I appended to the BODY element and my script wasn't a direct child of BODY. The fix is simple - either move your script to be a direct child (1st child) or BODY or use a different tag. In my case I needed the JavaScript be executed near the bottom so moving wasn't an option. I simply changed the tag.

function insertDiv() {
var s = document.getElementsByTagName("a")[0];
var js = document.createElement("div");
js.setAttribute('id', 'TipLayer');
js.setAttribute('style', 'visibility:hidden;position:absolute;z-index:1000;top:-100' );
s.appendChild(js);
}

The code above works in both IE and FF by appending at an "a" element instead of the body element. The TipLayer div I am inserting doesn't need to be in a specific location since it is hidden at start.

Trackback(0)
feed2 Comments
John
June 18, 2008
24.191.57.21
Votes: +0

Well, you wrote the code that caused my browser to crash. So, I think that would make you a co-discoverer, and me the discoverer. smilies/grin.gif

report abuse
vote down
vote up
Jordan
June 18, 2008
209.42.180.117
Votes: +0

lol, that is true.

report abuse
vote down
vote up

Write comment
 
 
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger
 

security image
Write the displayed characters


busy