我怎样才能关闭子窗口,如果关闭父窗口? [英] How can I close the child window if the parent window is closed?

查看:114
本文介绍了我怎样才能关闭子窗口,如果关闭父窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有弹出另一个窗口的Web应用程序。

如果对方关闭了主浏览器窗口,我需要关闭子窗口也是如此。

I have a web application that pops up another window.
If the person closes the main browser window, I need to close the child window as well.

这可能吗?如果是这样,怎么样?

Is this possible? If so, how?

推荐答案

当你调用window.open()的返回值是一个句柄创建的新窗口。利用这一点,你可以保持你已经打开的窗口的数组,然后卸载事件处理程序中调用close他们:

When you call window.open(), the return value is a handle to the new window that was created. Using this, you can keep an array of windows you have opened, and then call close on them within an unload event handler:

var win = winodw.open(URL, title, options);
window.MyOpenWindows.push(win);

后来,在卸载事件注册的功能:

Later, in a function registered for the unload event:

function closeWindows(){
    for (i=0;i<window.MyOpenWindows.length;i++)
    {
    	window.MyOpenWindows[i].close();
    }
}

这篇关于我怎样才能关闭子窗口,如果关闭父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆