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?
 
leakim971Connect With a Mentor PluritechnicianCommented:
what don't you want from http://jsfiddle.net/6wc4b/3/ ?
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
0
 
leakim971PluritechnicianCommented:
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

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
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?
0
 
leakim971PluritechnicianCommented:
if the child open itself window, you need to do the same thing but you talk about main page opening window
0
 
Gareth_PointonAuthor Commented:
Hi,

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

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

work : http://jsfiddle.net/6wc4b/3/
0
 
Gareth_PointonAuthor Commented:
I need to be able to close the child windows from the Parent opener.
0
 
Gareth_PointonAuthor Commented:
Ar sorry I see..

Can it close them all?
0
 
leakim971PluritechnicianCommented:
At this point you should try to understand the code...
0
 
Gareth_PointonAuthor Commented:
Yes I see just removing the value
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.