如何在Chrome中检测弹出窗口拦截器?

我在堆栈溢出中搜索了很多问题,并且可能在这里重复 检测Popup

但在Chrome测试中not helped for me (测试版本v26.0.1410.64)
以下方法Worked in IE and Firefoxnot 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的更好的解决方案吗?

最后,它通过结合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); 

试试下面.. !!

 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中阻止的弹出窗口

如何检测是否在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!'); } 

我知道这是“已解决”,但这个简单的代码可以帮助我检测Chrome中的“更好的弹出窗口阻止程序”扩展程序:

  if (!window.print) { //display message to disable popup blocker } else { window.print(); } } 

奥卡姆剃刀! 或者我错过了什么,这可能不是这么简单?

我曾使用这种方法从js打开窗口而不是被Chrome阻止。 http://en.nisi.ro/blog/development/javascript/open-new-window-window-open-seen-chrome-popup/

以下代码适用于chrome,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(); } } });