aspose file tools*
The moose likes Servlets and the fly likes How to know if user closes the browser window in servlets 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 » Java » Servlets
Bookmark "How to know if user closes the browser window in servlets" Watch "How to know if user closes the browser window in servlets" New topic
Author

How to know if user closes the browser window in servlets

GK
Greenhorn

Joined: Jan 25, 2001
Posts: 26
How do I know thru servets if a user closes its browser window?
Gunjan
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
As far as I know, it's not possible.
Andre Moo
Greenhorn

Joined: Sep 29, 2001
Posts: 22
Yes, this is not a Servlet issue.
There is no way of knowing whether the user has closed the browser window regardless of the server-side technology you use - jsp/servlets/asp/coldfusion/php/perl etc.
Hence the introduction of "sessions" in languages like asp/servlets/coldfusion to try and overcome this inherent limitation due to the nature of HTTP. It is up to the developer to set a sensible session "time-out".
Technically, however, there is a very poor and very un-elegant way of determining when the browser is closed which is highly un recommended - it is possible using client-side scripting e.g JavaScript or JScript, to detect when the browser window is closing and then do something - like open another window!(you may have experienced this on annoying sites with advert popup windows) When you open up the new window, you could point it to a url which then signals to the server that the user had closed the original browser window. Make sense? I don't recommend you implement this!
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
I have to agree with Andre 100%. I have tryed numerous versions of JavaScript to catch this event & every one of them is just loaded with bugs....Stick with sessions & session listeners & life will be much easier
 
Don't get me started about those stupid light bulbs.
 
subject: How to know if user closes the browser window in servlets
 
Similar Threads
Closing the browser
Session handling
session object
Session Invalidate -- Many ways
How to track browser close