jQuery in Action, 3rd edition
The moose likes HTML, CSS and JavaScript and the fly likes Catching the browser close action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic

Catching the browser close action

Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 116
Hi All,
I want to catch the browser close button action. Let me explain the scenario first. When a user clicks on the close button of a browser, I want to send an ajax call to set his loginStatus to false in the database. I can do it with the js event of onbeforeunload, but that has too many problems. The biggest being, when I navigate to some other site say google.com, it will set the login status to false, but then when I click on the back button, the session should remain there (ideally), but its logged out.

Any ideas on how to hunt for the solution?

Regards, Fawad Ali.
Software Engineer, Stafona Inc. - My Blog
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

This has been discussed dozen and dozens of times. Please search for previous discussions. The bottom line is that there is no way to determine when the browser has been closed.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link: http://aspose.com/file-tools
subject: Catching the browser close action
jQuery in Action, 3rd edition