aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Browser closed detection " Watch "Browser closed detection " New topic
Author

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.


SCJP 6
David Newton
Author
Rancher

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
 
Similar Threads
Why so much hype?
enforcing to enable javascript
How to prevent to click multi submit button?
How to get environment variable?
How do i trap the event of a browser window getting closed ?