问题
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?
回答1:
Run your code in a domready/onload event handler.
回答2:
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.
回答3:
The HTML in the page was not well formed. Please ignore the question.
来源:https://stackoverflow.com/questions/551511/how-to-overcome-ie-bug-when-dynamically-attaching-div-to-body-from-script