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
Gareth_PointonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
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
leakim971MultitechnicianCommented:
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_PointonAuthor Commented:
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 Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

leakim971MultitechnicianCommented:
if the child open itself window, you need to do the same thing but you talk about main page opening window
Gareth_PointonAuthor Commented:
Hi,

A Little stuck as I cannot get this code to fire.
windowsclose.txt
leakim971MultitechnicianCommented:
yes that can't work, you should try my code
Gareth_PointonAuthor Commented:
How does your code fit together as tried yours and couldn't get that to work?
leakim971MultitechnicianCommented:
Test page : http://fiddle.jshell.net/63qDd/4/show/
http://jsfiddle.net/63qDd/4/

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

work : http://jsfiddle.net/6wc4b/3/
Gareth_PointonAuthor Commented:
I need to be able to close the child windows from the Parent opener.
leakim971MultitechnicianCommented:
what don't you want from http://jsfiddle.net/6wc4b/3/ ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gareth_PointonAuthor Commented:
Ar sorry I see..

Can it close them all?
leakim971MultitechnicianCommented:
At this point you should try to understand the code...
Gareth_PointonAuthor Commented:
Yes I see just removing the value
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.