javascript - 将 DOM 节点移动到弹出窗口

标签 javascript jquery dom popup

我正在尝试将 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/

相关文章:

javascript - 链接对象时如何使用相同的方法?

javascript - 如何使用ajax post请求从输入中放入参数?

jquery - 如何将背景颜色更改为 <DIV/> 然后淡出,最后从 DOM 中删除?

javascript - Devtools > Elements > Properties 中的附加 DOM 子类别是否有实际用途?

yii2 中的 JavaScript 没有响应

javascript - ES6 将一个数组的元素归约成一个数组,其元素出现的频率

javascript - 如何将多个类名添加到 nextjs 元素

jquery - 如何通过使用 jQuery 测试复选框的高值和低值来检查复选框?

php - 每 24 小时执行一个 php 页面

JavaScript DOM 如何实现?