0

I have a JSP page A. And on page A, there are some links when click on them, page B or C will be popped up.

Now I have a javascript to run in page A. How can this javascript determine whether there are existing popup page B or C?

David Ruan
  • 534
  • 4
  • 18

1 Answers1

0

First of all you need to ensure that you have references to your opened windows available with you. It is currently not possible to get a list of already open window. If you are unsure you can refer to this answer that suggests a decent way of doing this.

Now, using the window object of the child window, you can check if it is null or not in order to know whether it is open or not:

var myWindow = window.open("https://www.google.com", "MsgWindow", "width=200,height=100");

function IsWindowClosed (win) {
    return win.window == null;
}

console.log("Window is closed: ", IsWindowClosed(myWindow));

Here's a working fiddle: https://jsfiddle.net/6vhgpkmm/1/

Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55