Javascript – Check whether a window is Popup or not


This question is not the duplicate of if window is popup , But a similar one.

I am developing a extension which injects scripts to all web pages. I need to detect whether the window is popup or not.

I am not the one who is opening the popup window, So the above solution won't work.

Best Solution

I've found that some browsers will set window.opener to window in certain cases. This is the most reliable popup check that I am using right now.

if (window.opener && window.opener !== window) {
  // you are in a popup