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
JavaScriptHTMLASP

Avatar of undefined
Last Comment
Gareth_Pointon

8/22/2022 - Mon
Big Monty

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
leakim971

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

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?
Your help has saved me hundreds of hours of internet surfing.
fblack61
leakim971

if the child open itself window, you need to do the same thing but you talk about main page opening window
Gareth_Pointon

ASKER
Hi,

A Little stuck as I cannot get this code to fire.
windowsclose.txt
leakim971

yes that can't work, you should try my code
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gareth_Pointon

ASKER
How does your code fit together as tried yours and couldn't get that to work?
leakim971

Test page : http://fiddle.jshell.net/63qDd/4/show/
http://jsfiddle.net/63qDd/4/

I added/created the global object windows : window.windows = {};
Gareth_Pointon

ASKER
What about the Close?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
leakim971

which close? you've a close button on the two child windows to close their brother
Gareth_Pointon

ASKER
I need to close the two windows that have been opened form the parent.
leakim971

only parent or child can close the window
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gareth_Pointon

ASKER
Yes and I'm trying to close the popups that are created from the parent on the parent.
Gareth_Pointon

ASKER
leakim971

- opener is useless in the parent window

work : http://jsfiddle.net/6wc4b/3/
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Gareth_Pointon

ASKER
I need to be able to close the child windows from the Parent opener.
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Gareth_Pointon

ASKER
Ar sorry I see..

Can it close them all?
leakim971

At this point you should try to understand the code...
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gareth_Pointon

ASKER
Yes I see just removing the value