【问题标题】:opening a popup in IE - "Member not found"在 IE 中打开一个弹出窗口 - “找不到成员”
【发布时间】:2009-06-12 16:14:29
【问题描述】:
【问题讨论】:
标签:
javascript
internet-explorer
pdf
popup
【解决方案1】:
我想我有一个更好的解决方案,它不需要先关闭窗口。问题是,如果您尝试使用空 URL(即“”)再次打开一个窗口(PDF 或其他),IE 不会覆盖它。但是,它将覆盖具有非空 URL 的 PDF。这可能是一个文件,但 about:blank 效果更好(这是空 URL 通常的作用)。
根据您的代码编写方式,您可能仍需要 try/catch,但这应该消除了这种需要:
windowHandle = window.open('about:blank',name,attributes);
windowHandle.document.location.href = url;
windowHandle.focus();
about:blank 将强制 PDF 退出子窗口并允许您执行您需要执行的操作。将 URL 和 focus() 的设置放在 windowHandle.onload() 处理程序中可能不是一个坏主意,因此处理 PDF 没有任何时间问题。即:
windowHandle.onload=function(){
windowHandle.document.location.href = url;
windowHandle.focus();
};
【解决方案2】:
我使用 try catch 块解决了这个问题。
windowHandle = window.open('',name,attributes);
try {
windowHandle.document.location.href = url;
} catch (exc) {
windowHandle.close();
windowHandle = window.open('',name,attributes);
windowHandle.document.location.href = url + suffix;
}
windowHandle.focus();
似乎对我有用。