Solved

HTML Close window

Posted on 2014-01-09
20
315 Views
Last Modified: 2014-01-10
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
Comment
Question by:Gareth_Pointon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
20 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39769274
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
 
LVL 82

Expert Comment

by:leakim971
ID: 39769310
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
 

Author Comment

by:Gareth_Pointon
ID: 39770614
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
Independent Software Vendors: 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!

 
LVL 82

Expert Comment

by:leakim971
ID: 39770667
if the child open itself window, you need to do the same thing but you talk about main page opening window
0
 

Author Comment

by:Gareth_Pointon
ID: 39770674
Hi,

A Little stuck as I cannot get this code to fire.
windowsclose.txt
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39770679
yes that can't work, you should try my code
0
 

Author Comment

by:Gareth_Pointon
ID: 39770744
How does your code fit together as tried yours and couldn't get that to work?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39770762
Test page : http://fiddle.jshell.net/63qDd/4/show/
http://jsfiddle.net/63qDd/4/

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

Author Comment

by:Gareth_Pointon
ID: 39770938
What about the Close?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39770955
which close? you've a close button on the two child windows to close their brother
0
 

Author Comment

by:Gareth_Pointon
ID: 39770963
I need to close the two windows that have been opened form the parent.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39770970
only parent or child can close the window
0
 

Author Comment

by:Gareth_Pointon
ID: 39770974
Yes and I'm trying to close the popups that are created from the parent on the parent.
0
 

Author Comment

by:Gareth_Pointon
ID: 39770981
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39771003
- opener is useless in the parent window

work : http://jsfiddle.net/6wc4b/3/
0
 

Author Comment

by:Gareth_Pointon
ID: 39771025
I need to be able to close the child windows from the Parent opener.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 200 total points
ID: 39771041
what don't you want from http://jsfiddle.net/6wc4b/3/ ?
0
 

Author Comment

by:Gareth_Pointon
ID: 39771081
Ar sorry I see..

Can it close them all?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39771085
At this point you should try to understand the code...
0
 

Author Comment

by:Gareth_Pointon
ID: 39771089
Yes I see just removing the value
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question