JavaScript method to check if pop ups are blocked

  • 2020-05-16 06:15:04
  • OfStack

It's useful to have a pop-up window. The problem for developers of such sites is that they don't know if the pop-ups are blocked by the browser or various browser plug-ins. Of course, the browser notifies the user, but this rarely gets the user's attention. Here's a simple way to test if your popup is blocked.

The JavaScript


var windowName = 'userConsole';
var popUp = window.open('/popup-page.php', windowName, 'width=1000, height=700, left=24, top=24, scrollbars, resizable');
if (popUp == null || typeof(popUp)=='undefined') {  
 alert(' Please unblock the window and click the link again. ');
}
else {  
 popUp.focus();
}

Step 1 is the normal pop-up window and captures the window handle to see if the handle object exists. If it exists, thank god. If it does not exist, we suggest that the user should close the pop-up window blocking Settings and click the link again. Of course, you can use a more persuasive message to inform your users. Or you can use a pop-up layer to display information.


Related articles: