更大的問題是,您嘗試在新窗口中打開的頁面與用戶已在查看的窗口相同,這沒有任何意義。更重要的是,如果彈出窗口阻止程序未阻止窗口創建,則會彈出一個無限循環(加載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.
}