detect-popup-blocker-using-javascript

Popups are sometimes good. Sometimes we want to show our data on popups or want to give some functionality which creates popups. But it becomes a tedious job when user’s popups are blocked by default by their browsers. In such situations we can alert users to enable their popups by unblocking them for your website.

Here is a small snippet using which we can easily check if popup blocker of client browser is on/off. Here we are using a simple javascript. we will make a user defined function and will open a window using javascript’s window.open() function and will try to open any random url (www.google.com in below example) and will see whether it returns true or false.

If window.open() returned false that means popup blocker of user’s browser is active. So here we will ask user to enable it and if window.open() returned true that means browser is allowing to open popups, so as soon as we will open he url (www.google.com here) in a popup window we will close it.

Here is complete code:

how to check popup blocker using javascript