admin管理员组

文章数量:1326326

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.

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.

Share Improve this question edited Aug 6, 2011 at 6:18 Eyad Fallatah asked Aug 5, 2011 at 22:24 Eyad FallatahEyad Fallatah 1,9484 gold badges24 silver badges36 bronze badges 2
  • Do you get an error when it doesn't work? what is the value of opener when you think it should work but it doesn't? – Dan Davies Brackett Commented Aug 6, 2011 at 0:02
  • The value of opener is [object DOMWindow] even though the window is not popup. – Eyad Fallatah Commented Aug 6, 2011 at 6:18
Add a ment  | 

1 Answer 1

Reset to default 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';
}

本文标签: javascriptif window is popupStack Overflow