• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript to detect browser closing

 
c ccc
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i need to have a way to detect the browser closing event, so I can invoke my servlet to update the database ( time the user spent for the application). i tried to use onunload to trigger the servlet, but, it actually triggers for the back button clicking, reload, and any link clickings as well. Is there a way, javascript can detect the close button clicking only?

thanks a lot.

cc
 
fred rosenberger
lowercase baba
Bartender
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
c ccc,

welcome to the Javaranch. You may not have noticed our naming policy on the way in. it requires a real sounding first and last name, although a first name initial is ok. please go here and update your screen name.

edit - i just noticed you have been asked before to change your name.

Second, i'm not sure this is the best forum for this question. I'm going to see about getting it moved to a more appropriate venue, where hopefully you can get the help you need.
[ January 12, 2006: Message edited by: fred rosenberger ]
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's move this beaut to s ssservlets.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it'd be more appropriate in the HTML forum, where this very subject has been broached many a time.

Moving forward (or is it a redirect? ) ...
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no real way to detect it.

Rely on your session end event on the server.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic