aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes javascript to detect browser closing Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "javascript to detect browser closing" Watch "javascript to detect browser closing" New topic
Author

javascript to detect browser closing

c ccc
Greenhorn

Joined: Dec 23, 2005
Posts: 2
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

Joined: Oct 02, 2003
Posts: 10043
    
    6

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 ]

Never ascribe to malice that which can be adequately explained by stupidity.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Let's move this beaut to s ssservlets.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56554
    
  14

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? ) ...


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    6
There is no real way to detect it.

Rely on your session end event on the server.

Eric
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: javascript to detect browser closing
 
Similar Threads
How to close a child window through the servlet?
Javascript Back button
Clear firefox cookies on closing the window
JWebUnit: How do I simulate clicking enter in a text field?
How to catch browser close event?