Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Browser closed detection

 
S Ali
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic