Categories
JavaScript Answers

How to detect if a browser is blocking a popup with JavaScript?

Spread the love

To detect if a browser is blocking a popup with JavaScript, we check various property of the window.

For instance, we write

const newWin = window.open(url);

if (!newWin || newWin.closed || typeof newWin.closed === "undefined") {
  //...
}

to call window.open to open url in a new window.

Then if newWin is undefined, or closed is true, or closed is undefined, then the popup window is blocked.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *