lois6b lois6b - 2 months ago 9
Javascript Question

Adapting IE8 to IE11

I have this code:

container = document.getElementById("menuContainer");


and later on:

container.document.open("text/html");
container.document.writeln(content);
container.document.close();


In IE8 works but in IE11 warns me:

enter image description here

What can I do?

Answer

The recommended standard reference from the node to a document has been node.ownerDocument since DOM Level 2. According to MSDN: ownerDocument is supported since IE6. In IEs node.document was also supported until IE10.

The fix for your code would hence be:

container.ownerDocument.open(...);

document.write was used in the example only to demonstrate the output, not as real code, hence I'm not handling its use in this answer.

Comments