Internet Explorer and the "Unknown runtime error"
Unknown runtime error
Even better, if I switched to IE7 compatibility mode I got the old:
The following line of code works and displays the expected output:
document.write('<p id="extraNote"><div class="somethingSpecial">Hello</div></p>');
And the following works as expected in all browsers except IE:
// Done when the page is initially displayed document.write('<p id="extraNote"></p>'); // Done in a seperate function that works out what should really go in extraNote var note = document.getElementById("extraNote"); note.innerHTML='<div class="somethingSpecial">Hello</div>';
Having worked out why IE was being annoying, the fix was very simple...
replace <p id="extraNote"> with <div id="extraNote">
... but it's obvious IE8 still has random IEisms, and proves that when it comes to supporting IE, that even now you have to fully test even the most minor of code changes (extraNote used to be a table cell rather than a paragraph i.e. <td id="extraNote">).
Update: Just checked the IE Programming Bugs Wiki and see that this is apparently "by design" - "Can't put invalid HTML in the document: You cannot assign a string to innerHTML or outerHTML that contains invalid HTML. For example, trying to replace the content of the P element with another P will fail. A P element can only contain text and inline elements. However, replacing the entire P element with another P would work just fine."
This seems like a very wierd limitation, especially as it's possible to edit the DOM directly and create a <div> within a <p> tag in IE, but there we go. Case closed I guess.Theo Gray on June 1, 2009 | Permalink | Comment