Solved

HTML Close window

Posted on 2014-01-09
20
312 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

831 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