简体   繁体   English

如何检查儿童窗的存在

[英]How to check the existence of Children Window

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. 我有一个JSP页面A。在页面A上,单击某些链接时,将弹出页面B或C。

Now I have a javascript to run in page A. How can this javascript determine whether there are existing popup page B or C? 现在,我有一个可在页面A中运行的javascript。此javascript如何确定是否存在弹出页面B或C?

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: 现在,使用子窗口的窗口对象,可以检查它是否为null以便知道它是否处于打开状态:

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/ 这是一个有效的小提琴: https : //jsfiddle.net/6vhgpkmm/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM