Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing windows in JavaScript

 
Brian Quinn
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I handle multiple pop up windows so you are able to close them.



Eric
 
Brian Quinn
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if this would help you, but I ran this



Eric
 
Brian Quinn
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic