This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Closing windows in JavaScript

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic