How to close a child window if the parent window is closed?

I have a web application that appears in another window.
If a person closes the main browser window, I also need to close the child window.

Is it possible? If so, how?

+3
source share
2 answers

When window.open () is called, the return value is a handle to the newly created window. Using this, you can save an array of windows that you opened, and then close them in the unload event handler:

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

Later in the function registered for the unload event:

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

Source: https://habr.com/ru/post/1710779/


All Articles