[英]jQuery throws SCRIPT5022: HierarchyRequestError when attempted to append a jQuery object on Internet Explorer ( IE)
[英]Internet Explorer throws SCRIPT5022: HierarchyRequestError when trying to appendChild an HTML object from another window
我有一个窗口中的 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:层次结构请求错误
我搜索了错误代码,这里列出:
http://msdn.microsoft.com/en-us/library/ie/gg592979(v=vs.85).aspx
它说我无法在该位置插入节点。 但是,上面的代码在 Firefox 和 Chrome 中运行良好。
这里发生了什么以及我如何解决它?
谢谢,
PS:我使用的是 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');
}
}
上述解决方案的问题是IE版本不支持innerHTML和outerHTML
这个问题不再有效。 Microsoft 已停用 Internet Explorer。 感谢所有的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.