我已经搜查了许多问题堆栈溢出,并可能会在这里重复 检测弹出
但not helped for me
,而在Chrome测试(测试v26.0.1410.64)
下面的方法Worked in IE and Firefox
,但not in 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也适用?
最后,它成功通过不同的答案从#1的成员组合
此代码为我工作与在测试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);
试试下面..!
var pop = window.open("about:blank", "new_window_123", "height=150,width=150");
// Detect pop blocker
setTimeout(function() {
if(!pop || pop.closed || pop.closed == "undefined" || pop == "undefined" || parseInt(pop.innerWidth) == 0 || pop.document.documentElement.clientWidth != 150 || pop.document.documentElement.clientHeight != 150){
pop && pop.close();
alert("Popups must be enabled.");
}else{
alert("Popups is enabled.");
pop && pop.close();
}}, 1000);
看看下面的问题
检测在Chrome封锁弹出
如何检测是否弹出窗口中会阻止铬
在谷歌这将更加有助于你..
https://www.google.com/search?q=how+to+detect+a+blocked+popup+in+chrome
我发现它更有效的使用try-catch代码如下:
var popup = window.open(winPath,winName,winFeature,true);
try {
popup.focus();
} catch (e) {
alert('popup blocked!');
}
我知道这是“解决”,但这个简单的代码为我工作检测铬“更好的弹出窗口拦截”扩展名:
if (!window.print) {
//display message to disable popup blocker
} else {
window.print();
}
}
奥卡姆剃刀! 还是我失去了一些东西,它不可能这么简单?
我曾用这种方法打开从JS窗户和不beeing阻止Chrome浏览器。 http://en.nisi.ro/blog/development/javascript/open-new-window-window-open-seen-chrome-popup/
下面的代码工作在铬,Safari和Firefox。 我已经使用jQuery的这一点。
var popupWindow = window.open("http://www.google.com","directories=no,height=100,width=100");
$(document).ready(function(e) {
detectPopup();
function detectPopup() {
if(!popupWindow) {
alert("popup will be blocked");
} else {
alert("popup will be shown");
window.open('','_self');
window.close();
}
}
});