Popup detection before user login

Is there a good way to determine if a person has a pop-up blocker enabled? I need to support a web application that, unfortunately, has a lot of pop-ups on it, and I need to check if the pop-up blocker is activated.

The only way I found this is to open a window from javascript, check if it opens to determine if the lock is on and then close it right away.

This is a bit annoying, as users who don't have one see a small flash on the screen when the window opens and closes right away.

Are there any other unobtrusive methods for this?

+6
javascript browser popup
source share
5 answers

Read Javascript Popup Blocker Detection :

Basically you check to see if the window.open method returns the handle to the window just opened.

Looks like:

var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no'); if(mine) var popUpsBlocked = false else var popUpsBlocked = true mine.close() 
+6
source share

As others have already said, you will have to try and see, but checking that the resulting window object is "false" is not enough for all browsers.

Opera still returns a Window object when the popup is blocked, so you just need to inspect the object to determine if this window is valid:

 var popup = window.open(/* ... */); var popupBlocked = (!popup || typeof popup.document.getElementById == "undefined"); 
+3
source share

As others commented, the only way to make sure of this is to try.

However, a good rough answer to the question "is a pop-up blocker," these days is yes. All recent browsers will block your pop-ups by default, so you better design your application to handle this gracefully. Namely, do not try window.open, with the exception of the reaction to user interaction (usually onclick), and everything will be fine.

+2
source share

I don’t think there is any way to detect this without trying to open the window as popup blockers do not add anything that can be polled in JS.

+1
source share

Pop-ups that are opened in response to a user action, for example, clicking on a link, should not be blocked by pop-up blockers.

0
source share

All Articles