简体   繁体   中英

Close all children windows browser from another window

This is my scenario: I've a tab in my browser (IE8) and if I click on a link, I open a new window (window's name: " Win2 "). Now, i came back to the first window, open a new tab in my browser, go to another page and click to a different link. Once click on the last link, I want to close the page " Win2 ". Can I do it with Javascript? How I can acces to the 1st-page's children from another page? Backend-side, I use Java 1.5 with framework struts.

Save the return value of every call to window.open:

var windows = {};

windows.Win2 = window.open("...", "Win2");

To close all of them:

for (var name in windows) {
    if (windows.hasOwnProperty(name)) {
        windows[name].close();
        windows[name] = null;
    }
}

Or to close one:

windows.Win2.close();

You can store the opened window in a variable in your parent window.

var Win2 = window.open("", "Win2");

Then you can close it later on using the variable.

Win2.close();

If you want to close Win2 from a different child window of the original parent. Create a function on your parent window, then call it from the child.

Parent Window

function CloseWin2() {
    Win2.close();
}

Child Window

if(window.opener) {
    window.opener.CloseWin2();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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