Link to home
Start Free TrialLog in
Avatar of Gareth_Pointon
Gareth_Pointon

asked on

HTML Close window

Hi,

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.

Thanks
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.

http://www.codelodge.net/2012/11/closing-all-child-windows-using.html
the child ask the parent to close

opener.closeAllButNotMe("myName");

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

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";
window.windows[name] = window.open(url, name, params);

// somewhere else
var name = "otherName";
windows[name] = window.open(url, name, params);

Open in new window

Avatar of Gareth_Pointon
Gareth_Pointon

ASKER

Hi,

Regarding the following script:


// somewhere else
var name = "otherName";
windows[name] = window.open(url, 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
Hi,

A Little stuck as I cannot get this code to fire.
windowsclose.txt
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 : http://fiddle.jshell.net/63qDd/4/show/
http://jsfiddle.net/63qDd/4/

I added/created the global object windows : window.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 : http://jsfiddle.net/6wc4b/3/
I need to be able to close the child windows from the Parent opener.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
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