[英]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.