• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

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
0
Gareth_Pointon
Asked:
Gareth_Pointon
  • 10
  • 9
1 Solution
 
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
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
leakim971PluritechnicianCommented:
what don't you want from http://jsfiddle.net/6wc4b/3/ ?
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now