gpt4 book ai didi

javascript - Internet Explorer 抛出 SCRIPT5022 : HierarchyRequestError when trying to appendChild an HTML object from another window

转载 作者:太空宇宙 更新时间:2023-11-04 13:46:55 25 4
gpt4 key购买 nike

我有一个来自一个窗口的 html 表格。我通过使用

获取表格
var table = document.getElementById('tableId');

然后我打开另一个窗口使用:

window.open('newWindow.html'); 

在此窗口中,有一个 id = divId 的 div。

现在,如果我尝试通过以下代码从另一个窗口附加表格:

var cloneTable = jQuery.extend(true, {}, window.opener.table);

var div = document.getElementById('divId');

div.appendChild(cloneTable);

Internet Explorer 将抛出此错误:

SCRIPT5022: HierarchyRequestError

我已经搜索了错误代码,列在这里:

http://msdn.microsoft.com/en-us/library/ie/gg592979(v=vs.85).aspx

它说我不能在那个位置插入节点。但是,上述代码在 Firefox 和 Chrome 中运行良好。

这里发生了什么,我该如何解决?

谢谢,

附言:我使用的是 IE 10

最佳答案

IE 可能无法在不同文档之间移动元素。如果浏览器无法克隆表格,您可以使用 outerHTML 属性。

例如

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');
}
}

关于javascript - Internet Explorer 抛出 SCRIPT5022 : HierarchyRequestError when trying to appendChild an HTML object from another window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23097024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com