Link to home
Start Free TrialLog in
Avatar of Gareth_Pointon

asked on

HTML Close window


Basic one but cannot get my head on it.

I have a main page that opens other windows. I would like to help the login page close all other windows that not the parent.

Avatar of Big Monty
Big Monty
Flag of United States of America image

you need to keep track of all of your windows that you open, then you'll be able to close the ones you want. There's no way to automatically close all child windows without keeping track of them.

Here's a good tutorial that keeps track of the child windows, then a function to close them.
the child ask the parent to close


window.closeAllButNotMe = function( dontCloseMeName ) {
    for(windowName in {
         if( windowName != dontCloseMeName ) {
                 var windowObj =[ windowName ];

Open in new window

when you open a window, you need to save its name and instance
you save this in a global var, in my example it's windows

var name = "login";[name] =, name, params);

// somewhere else
var name = "otherName";
windows[name] =, name, params);

Open in new window

Avatar of Gareth_Pointon



Regarding the following script:

// somewhere else
var name = "otherName";
windows[name] =, name, params);

If this for the subsequent windows opened from the child?
if the child open itself window, you need to do the same thing but you talk about main page opening window

A Little stuck as I cannot get this code to fire.
yes that can't work, you should try my code
How does your code fit together as tried yours and couldn't get that to work?
Test page :

I added/created the global object windows : = {};
What about the Close?
which close? you've a close button on the two child windows to close their brother
I need to close the two windows that have been opened form the parent.
only parent or child can close the window
Yes and I'm trying to close the popups that are created from the parent on the parent.
- opener is useless in the parent window

work :
I need to be able to close the child windows from the Parent opener.
Avatar of leakim971
Flag of Guadeloupe image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ar sorry I see..

Can it close them all?
At this point you should try to understand the code...
Yes I see just removing the value