javascript - 在 iframe 中加载网站在 IE 中出现错误

标签 javascript internet-explorer iframe popup

我有一个网址,想要加载到弹出窗口内的 iframe 中。父窗口有一个脚本,该脚本会向弹出窗口插入脚本,以便弹出窗口在关闭时刷新父窗口。

function popUp(url) {
    newwindow = window.open('', 'mypopup', '');
    var tmp = newwindow.document;
    tmp.write('<!DOCTYPE html><html><head><title>My Pop-Up</title></head>');
    tmp.write('<body><iframe src="' + url + '" scrolling="no" frameborder="0"></iframe>');
    tmp.write('<script type="text/javascript">window.onunload = function(){ window.opener.location.reload(); }</script></body></html>');
    tmp.close();
}

我选择通过javascript编写html,因为我无法编辑正在加载的页面(我需要在弹出窗口关闭时真正重新加载父级。)这适用于chrome和firefox,但IE有错误' SCRIPT5:访问被拒绝。' 我并没有尝试访问 iframe 中正在加载的页面的任何部分,我只是想加载它。

当我在新的 IE 选项卡中打开页面时,它加载正常。另外,如果我通过 showModalDialog() 加载 url,页面就会加载。我希望我可以只使用 showModalDialog(),但是当单击弹出页面上的保存按钮时,会打开另一个弹出窗口,所以我想这是不可能的。

非常感谢您的帮助。

谢谢:)

最佳答案

好吧,如果您只想在弹出窗口关闭时进行检查,那么您可以启动外部计时器来检查:

var checkPopup = window.setInterval(function() {
    if (newwindow.closed) {
        window.clearInterval(checkPopup);
        document.location.reload();
    }
}, 100);

这样您就不必依赖弹出窗口本身内的花哨脚本。

关于javascript - 在 iframe 中加载网站在 IE 中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14953638/

相关文章:

html - iframe 属性 "allowfullscreen"的支持有多广泛?

javascript - canvas getImageData 在 Windows 上本地运行时不起作用? (安全异常(exception))

javascript - 如何将 JSON 字符串对象值转换为整数?

javascript - 如何使用 Angular 数据绑定(bind)将复选框绑定(bind)到选择禁用的属性?

html - ASP.NET MVC 2 RTM - 在 Internet Explorer 中不显示图标

css - CSS 中的 MS IE 相对路径语法

javascript - 淡入淡出在 FF 上有效,但在 IE 上无效

javascript - 如何根据视口(viewport)大小更改 Stripe 卡元素的格式

html - 从 Excel Embed iFrame 中删除底部栏

javascript - Uncaught ReferenceError : functionName is not defined