【问题标题】:reach content of new window.open到达新窗口的内容。打开
【发布时间】:2014-02-17 22:35:07
【问题描述】:

我新建了一个窗口

var win = window.open("", "", "width=400, height=200");

我想到达它的身体

var $windowBody = $(win.document.body);

然后使用.find()、.html()等方法

这适用于 FF 和 Chrome 但不适用于 IE。 还发现了related post这个。

如何在 IE 中解决这个问题?即,如何使这项工作跨浏览器?

jsFiddle - 注意关闭按钮永远不会出现在 IE 中。

【问题讨论】:

  • 你从 IE 得到什么样的错误?
  • @LuisMasuelli,Exception thrown and not caught。在问题中添加了一个 jsFiddle。
  • 您需要等待document.ready 状态才能对弹出窗口执行任何操作。 JavaScript 不会等待之前的语法完成。
  • @Allendar,你能解释更多/发布一个例子吗?您的意思是:jsfiddle.net/XL7LR/11 - 使用 onload 事件?
  • 应该是那种方式是的。我目前不在 Windows PC 附近,因此目前无法对其进行测试。似乎 JSFiddle 不能很好地处理这些机制。它也不能在我的 MacBook 上正确显示。

标签: javascript jquery internet-explorer


【解决方案1】:

请使用以下代码在 IE 中修复它

var content = $('#content');

$('#open').on('click', function () {

    var win = window.open("", "", "width=400, height=200");
    $newWindow = $(win.document.body);    
    $newWindow.html(document.getElementById("content").innerHTML);    
    $newWindow.find('#close').on('click', function () {
        win.close();
    });
});

或使用:

var content = $('#content');

// and then 
$newWindow.html(content);

【讨论】:

  • 做到了。谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-03
  • 1970-01-01
  • 2011-02-24
  • 1970-01-01
相关资源
最近更新 更多