What is going on?
There do appear to be additional security measures put in place for Internet Explorer 10. As for the DOMException.HIERARCHY_REQUEST_ERR
error, this has to do with attempting to put an object someplace the browser feels it doesn't belong. For instance, the following code will also raise this exception:
document.appendChild( document.createElement( "form" ) );
In this case, we cannot append a form
to the document
, hence the error. In your particular case, there appears to be a concern with adding objects generated in one window to another window.
The DOM Exception Error Codes reference describes this error as:
The node cannot be inserted at the requested location. Starting with Internet Explorer 10, the error-code string
HierarchyRequestError
is returned instead.
How do you get around it?
You have actually identified the appropriate modification to make; create elements from the context of the parent window. To avoid verbose lines of code, you could create a reference to the parent document
and that throughout your code:
var _doc = window.opener.document;
function addSpan () {
_doc.body.appendChild( _doc.createElement("span") );
}
This keeps the code from growing out of control with instances of window.opener.document
.