Solved

HTML Close window

Posted on 2014-01-09
20
300 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 32

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
Hi,

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

Expert Comment

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

Author Comment

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

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
What about the Close?
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
which close? you've a close button on the two child windows to close their brother
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Expert Comment

by:leakim971
Comment Utility
only parent or child can close the window
0
 

Author Comment

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

Author Comment

by:Gareth_Pointon
Comment Utility
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
- opener is useless in the parent window

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

Author Comment

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

Author Comment

by:Gareth_Pointon
Comment Utility
Ar sorry I see..

Can it close them all?
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
At this point you should try to understand the code...
0
 

Author Comment

by:Gareth_Pointon
Comment Utility
Yes I see just removing the value
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now