views:

133

answers:

3

I have the following scenario:

  1. A user on one our customer's website clicks a link. It performs an automatic signon with their credentials to our site, which is launched in a new window.
  2. User on our site logs out, and is sent to a page which does a JavaScript window.close(), which closes the window. If they were a customer that logged into our site directly then they would go back to the Login page, but being automatically signed on, they have no use for the Login page, so the page automatically closing is better.

However sometimes the following happens

  1. A user on one our customer's website clicks a link, performs an automatic signon with their credentials to our site, which launches in a new window.
  2. While in our application they click on the "Help" link, which at this time is another popup window.
  3. At some point they log out of our app, which closes that window.
  4. The help window is still open.
  5. The user clicks on a link in the help window.
  6. The user, not being logged in anymore, now goes to a login screen in that help window.
  7. MASS HYSTERIA!

So what I'd like to do is ensure that when that original window is closed, it also closes any popup windows it spawns. I figure this can be done in JavaScript but how?

ADDENDUM: The suggestions below are nice but the problem is the page the user is on when the browser closes is not the same page that spawns the popup, so the handles to the pages are all gone. How can I get the handle to a popup window with a specific name?

+1  A: 

Keep track of the window names you open the popups with.

Have a page that purely does a window.close()

When you would do a normal window.close(), make sure you do a window.open("our close page", windowNameIStored) for each of the popup windows.

This is a fix I submitted downstream to a vendor of ours and works quite well.

Dan McGrath
A: 

Stop using pop-ups, this isn't 1998 :)

Seriously, though with all of the built-in browser functionality and 3rd party apps which also block them, they've become pretty much unreliable. Are you 100% sure the pop-up opened? You'll have to test to make sure, but then maybe a 3rd party app closed it after your test finished, who knows, so now the customer is having a bad experience. If they're actually paying customers, your client could be losing money. Sure, you can put a message which says "turn off your pop-up blocker", but honestly how many users actually know how to do that?

Every time I'm asked to do a pop-up, I just stare at whoever requested it like they are speaking some other language, then ask if it is 1998. Pop-ups are the result of one or more of the following: bad User Interface design, ignorant managers, and/or sloppy/lazy development. Though I'm sure there are other reasons.

Just my 2-cents.

paulj
In this context though, a popup makes sense - at least when the user is coming to our site through automatic logon. They don't want to be routed out of their original session, just logged onto ours as well.Also this isn't an answer to the question and would have been better as a comment, just FYI
Schnapple
I agree partially... If the end-user is in something like extranet, it may be appropriate to open a new window for something outside the extranet. Using pop-ups for things like "help" sections, which he describes is what I was referring to as bad.
paulj
+2  A: 
<html>
<head>
<script>
var childwindows=new Array();
function openchild(){
    var childW=window.open('in.html');
    childwindows[childwindows.length]=childW;
}

function closewindow(){
    for(i in childwindows){
     if(childwindows[i] && !childwindows[i].closed) {childwindows[i].closewindow();}
    }
    window.close();
}
</script>
</head>
<body>
<br/>
<a onclick="openchild();">open child window</a>
<br/><br/>
<a onclick="closewindow();">close me</a>
</body>
</html>
vsr