我正在尝试将 DOM 节点从“根”页面移动到通过 window.open()
创建的新弹出窗口。这是我正在使用的代码。
var win = window.open('/Search/Print', 'printSearchResults'),
table = $('#printTable');
win.document.close();
setTimeout(function () {
var el = win.document.createElement("table");
el.innerHTML = table.html();
win.document.body.appendChild(el);
}, 40);
它在 Chrome 中有效,但在 IE8 中,我收到以下错误:“未知运行时错误。”
我也试过这种方法:
var p = window.open('/Search/Print', 'printSearchResults'),
table = $('#printTable');
setTimeout(function () {
p.document.body.appendChild(table.clone(false)[0]);
}, 100);
这样做,我在 IE8 中收到“不支持此类接口(interface)”。同样,Chrome 运行良好。
有没有人有办法实现我想要实现的目标?
为了完整起见,这里是弹出窗口的 HTML:
<!DOCTYPE html>
<html>
<head>
<title>Print Results</title>
</head>
<body>
</body>
</html>
最佳答案
我在 IE9(和 IE8/7 浏览器模式)上测试了您的代码。
代替 el.innerHTML = table.html();
使用 jquery $(el).html(table.html());
解决了这个问题。
关于javascript - 将 DOM 节点移动到弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11868765/