更大的问题是,您尝试在新窗口中打开的页面与用户已在查看的窗口相同,这没有任何意义。更重要的是,如果弹出窗口阻止程序未阻止窗口创建,则会弹出一个无限循环(加载green policy.html
,打开新的green policy.html
,加载green policy.html
等)。你想在哪里发生弹出?
此外,要添加到Russ Cam's answer,可以通过检查返回值window.open
来检测弹出窗口何时无法打开。我已经成功地在Firefox,IE,Opera和Safari中使用它(不需要在Chrome中测试)。使用提供的功能,这是我如何处理阻止的弹出窗口:
function MM_openBrWindow(theURL,winName,features) { //v2.0
if (!window.open(theURL, winName, features)) {
// Window failed to open:
// show a HTML dialog/popover that prompts the user to allow
// popups from this site, along with a `cancel` and `try again`
// button. The `try again` button will attempt to open the
// window again with the provided parameters
dialog.popupBlockedNotice.open(arguments);
}
// Window opened successfully.
}