views:

267

answers:

3

UPDATE: the HTML was not well formed. This was causing the script to appear in inner div. Please ignore the question.

IE ver<8 has a known bug (Internet explorer cannot display the page. Operation aborted) If a script tries to append something to upper level block:

The bug is described here:

Update: I rephrased the question and simplified the example:

The bug occurs in the following code:

[end of html file]
<script type="text/javascript" >
if (window.document.body){
    var c_div = window.document.createElement('div');
    window.document.body.appendChild(c_div); 
}
</script>

</body>

Question: This seems to me exactly similar to example1 Method1 In Microsoft workaround (here is the link again). How come I still have the bug? What am I missing here?

+7  A: 

Run your code in a domready/onload event handler.

ionelmc
Please read the update. According to Microsoft it should work without onload event. See above.
Nir
wouldn't make sense to change the dom before it is ready anyway
ionelmc
A: 

It might be a slightly insane approach but could you pull out the innerHTML of the entire <body> append your string to it and then set the <body> innerHTML to the new value?

May affect some previously attached JS events unless it's inline onclick stuff.

sanchothefat
hehe. I should vote myself down for that :P
sanchothefat
A: 

The HTML in the page was not well formed. Please ignore the question.

Nir