我有一个网址,想要加载到弹出窗口内的 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/