Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect popup blocker in Chrome?

I have searched many issue in stack overflow and might be duplicate here Detect Popup

But not helped for me while testing in Chrome (tested v26.0.1410.64)
Following Approach Worked in IE and Firefox but 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();
} 

Any better solution that works for Chrome also?

like image 395
Surendra Jnawali Avatar asked May 14 '13 09:05

Surendra Jnawali


People also ask

How can I detect if a browser is blocking a popup?

The only way to test if your browser is configured to show pop-up windows is to actually try to automatically open a pop-up window; this is why you might have either seen a "Pop-up Blocked" warning near your browser's Address Bar, or you may have seen a pop-up window flash on the screen briefly.

Where is the popup blocker located?

Under Privacy and security, click the Content Settings button. Select Pop-ups and redirects. To disable the pop-up blocker uncheck the Blocked (recommended) box. To enable pop-ups on specific sites, check Blocked (recommended) and click Add next to Allow and enter the URL(s).


1 Answers

Finally, it success by combining different answer from Stackoverflow's member
This code worked for me & tested in 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);
like image 53
Surendra Jnawali Avatar answered Sep 29 '22 10:09

Surendra Jnawali