[英]Internet Explorer throws SCRIPT5022: HierarchyRequestError when trying to appendChild an HTML object from another window
I have an html table from one window.我有一个窗口中的 html 表。 I get the table by using我通过使用得到表
var table = document.getElementById('tableId');
then I open another window by using :然后我使用以下方法打开另一个窗口:
window.open('newWindow.html');
In this window, there's a div with id = divId.在这个窗口中,有一个 id = divId 的 div。
Now if I tried to append the table from the other window by the following code :现在,如果我尝试通过以下代码从另一个窗口附加表格:
var cloneTable = jQuery.extend(true, {}, window.opener.table);
var div = document.getElementById('divId');
div.appendChild(cloneTable);
Internet Explorer will throw this error : Internet Explorer 将抛出此错误:
SCRIPT5022: HierarchyRequestError SCRIPT5022:层次结构请求错误
I have searched into the error code, listed here :我搜索了错误代码,这里列出:
http://msdn.microsoft.com/en-us/library/ie/gg592979(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/ie/gg592979(v=vs.85).aspx
It said I can't insert the node at that location.它说我无法在该位置插入节点。 However, the above code works fine in Firefox and Chrome.但是,上面的代码在 Firefox 和 Chrome 中运行良好。
What's happened here and how I can work around it ?这里发生了什么以及我如何解决它?
Thanks,谢谢,
PS: I'm using IE 10 PS:我使用的是 IE 10
IE is probably can't move elements across different documents. IE 可能无法在不同的文档中移动元素。 What you can do is to user the outerHTML property if the browser fails to clone the table.如果浏览器无法克隆表,您可以做的是使用 outerHTML 属性。
eg例如
var tbl = window.opener.table;
try {
document.getElementById('my_div').appendChild(tbl.cloneNode(true));
}
catch (e){
if (tbl.outerHTML) {
document.getElementById('my_div').innerHTML = tbl.outerHTML;
}
else {
console.log('not working');
}
}
上述解决方案的问题是IE版本不支持innerHTML和outerHTML
This question no longer valid.这个问题不再有效。 Internet Explorer has been retired by Microsoft. Microsoft 已停用 Internet Explorer。 Thanks for all the help.感谢所有的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.