我在堆栈溢出中搜索了很多问题并且可能重复这里Detect Popup
但是在 Chrome 中测试时对我没有帮助
(已测试 v26.0.1410.64)
以下方法 适用于 IE 和 Firefox
但 不适用于 Chrome
var popup = window.open(winPath,winName,winFeature,true);
if (!popup || popup.closed || typeof popup.closed=='undefined'){
//Worked For IE and Firefox
alert("Popup Blocker is enabled! Please add this site to your exception list.");
window.location.href = 'warning.html';
} else {
//Popup Allowed
window.open('','_self');
window.close();
}
还有适用于 Chrome 的更好解决方案吗?
最佳答案
最后,它通过结合 Stackoverflow 成员的不同答案而成功
此代码对我有用,并在 IE、Chrome 和 Firefox
var popup = window.open(winPath,winName,winFeature,true);
setTimeout( function() {
if(!popup || popup.outerHeight === 0) {
//First Checking Condition Works For IE & Firefox
//Second Checking Condition Works For Chrome
alert("Popup Blocker is enabled! Please add this site to your exception list.");
window.location.href = 'warning.html';
} else {
//Popup Blocker Is Disabled
window.open('','_self');
window.close();
}
}, 25);
关于javascript - 如何检测 Chrome 中的弹出窗口拦截器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16538991/