3

Is there a way to determine if the current window is a popup? This is what I have right now but for some reason it is not working. I am trying to make sure that certain pages are only shown in popup window.

if(!opener)
window.location = 'error.php';

The value of opener is [object DOMWindow] even though the window is not popup.

Eyad Fallatah
  • 1,859
  • 4
  • 22
  • 34

1 Answers1

8

Assuming you're opening popup windows yourself- set a flag:

var myWindow = window.open(...);
myWindow.isPopup = true;

then, in your popup window, check for the flag:

if (!window.isPopup) {
    window.location = 'error.php';
}
evan
  • 4,239
  • 1
  • 18
  • 18