views:

611

answers:

3

Suppose user has opened my web application in many different browser windows. After sometime he is timed out / sign out from the application.

I want to close all the related browser windows. How can we handle this?

(I think GMAIL does that)

A: 

Write a scriplet that when the focus is brought to the window (for your application) it checks to see if the session is still valid. If it is not, then send a command to close the window.

Elie
+1  A: 

If you maintain references to any child windows, you can use window.close() in combination with setTimeout().

As a note, you should probably exercise caution when closing users' windows, as it can potentially cause a bad user experience. Imagine that I've opened up my bank's website to look at the transactions for an account so that I can clear/reconcile them. But in the middle I run off to grab some lunch or something. When I come back, I find that all of my windows have been closed and I have to relogin, even though I didn't need to 'cause I was just looking at a relatively static list of data. Or even worse, if the window-closing isn't coded correctly, I might find that my browser has been closed entirely, which is definitely a bad experience.

Rob Hruska
A: 

Don't. As far as the typical user is concerned, your web site does not have the right to close the user's windows and they will HATE your site if you try. If you think that your web site's proper operation depends on being able to close the user's browser, then you are doing it wrong.

Furthermore, there is no way that you can count on the success of your attempt to close user windows or perform similar such actions. So spend your time making your web site work properly regardless of what the user does in the browser. Besides, it is easier that way.

Rob Williams
I agree with this in most cases (i.e. public web applications). However, we don't know the OP's context. If he/she has a customer for whom this is a requirement for,say, their internal web application, then it has to be done somehow unless the customer can be convinced otherwise.
Rob Hruska
Good point--I assumed public web application in the absence of information to the contrary. For an internal web app, I would at least advise the sponsor that this is a bad idea with the likely consequences.
Rob Williams