File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Closing windows in JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Closing windows in JavaScript" Watch "Closing windows in JavaScript" New topic
Author

Closing windows in JavaScript

Brian Quinn
Ranch Hand

Joined: Dec 23, 2003
Posts: 32
I have a web app that on occasion has 2 popup windows opened along with the main browser window. It works in the following manner - Main opens Popup 1, which may open Popup 2, if the user clicks on lick in popup 1. On occasion, the user's session may timeout so I take the active popup and provide them a button that should result in any popups being closed and the main window being reloaded. How do I check if there is more than 1 popup open at a time ?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
This is how I handle multiple pop up windows so you are able to close them.



Eric
Brian Quinn
Ranch Hand

Joined: Dec 23, 2003
Posts: 32
Eric,
Thanks, but I don't think that addresses my problem. My main window opens 1 window, which may open a second window (so the main window only opens 1). I may have a session time out , which will load a new page into the active window(either popup1 or popup2) telling the user that they will be logged out. The code I have only closes 1 popup:
funtion logout{
parent.window.reload();
top.window.close();
}
, but if the active window is the 2nd pop up, it just closes that one and returns to the 1st popup. I need a way to tell if which popup I'm in and close 1 or 2 of them and return the focus to the main browser window.
Since the logout message could load in either pop window, the script needs to check if this is the sub window or the sub sub window and I don't know how to do that

TIA,
Brian
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I am not sure if this would help you, but I ran this



Eric
Brian Quinn
Ranch Hand

Joined: Dec 23, 2003
Posts: 32
Thanks Eric
Ended up with the following:

if (top.opener.top.opener!=null){
top.opener.top.opener.location.reload();
top.opener.top.close()
top.window.close()
}
else{
top.opener.location.reload();
top.window.close();
}

This is working for me for the most part, but I have another ? - Given a window object, is it possible to find out how many child windows are open ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing windows in JavaScript
 
Similar Threads
Javascript Dependent Pop Up Problem
Popup window question
Redirecting from popup window
Popup window question
Check if popup window is already open from parent window?