wood burning stoves
The moose likes HTML, CSS and JavaScript and the fly likes Browser closed detection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Browser closed detection " Watch "Browser closed detection " New topic

Browser closed detection

S Ali
Ranch Hand

Joined: Aug 23, 2009
Posts: 129
Hi all,
I'm working on a two player game, now I need to know when one user closes his browser or his browser crashes down, the database should be modified to indicate game being over so that the other user doesn't wait for him forever.
How do I do that using JavaScript and sending data to database before a browser can close.
Also I learned that JavaScript function for closing the browser isn't guaranteed for all types of browsers so is there an easier way?
Thanks in advance.

David Newton

Joined: Sep 29, 2008
Posts: 12617

Not really; HTTP is stateless. If the browser crashes, there's nothing left to execute any JavaScript code. At best you could have a timer-based "keepalive" that would fail to fire if the browser disappeared, but obviously if the browser's gone, you're done executing JavaScript: state must be maintained on the server side (although you might be able to do something with cookies--not sure).
I agree. Here's the link: http://aspose.com/file-tools
subject: Browser closed detection
It's not a secret anymore!