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
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
the child ask the parent to close
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
opener.closeAllButNotMe("myName");
window.closeAllButNotMe = function( dontCloseMeName ) {
for(windowName in window.windows) {
if( windowName != dontCloseMeName ) {
var windowObj = window.windows[ windowName ];
windowObj.close();
}
}
}
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);
ASKER
Hi,
Regarding the following script:
If this for the subsequent windows opened from the child?
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
ASKER
yes that can't work, you should try my code
ASKER
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 = {};
http://jsfiddle.net/63qDd/4/
I added/created the global object windows : window.windows = {};
ASKER
What about the Close?
which close? you've a close button on the two child windows to close their brother
ASKER
I need to close the two windows that have been opened form the parent.
only parent or child can close the window
ASKER
Yes and I'm trying to close the popups that are created from the parent on the parent.
ASKER
I need to be able to close the child windows from the Parent opener.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ar sorry I see..
Can it close them all?
Can it close them all?
At this point you should try to understand the code...
ASKER
Yes I see just removing the value
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