?
Solved

HTML Close window

Posted on 2014-01-09
20
Medium Priority
?
326 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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
 
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 800 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

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!

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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 …
Suggested Courses

801 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