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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
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: 11479
    
  16

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 ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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: 61654
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    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://aspose.com/file-tools
 
subject: javascript to detect browser closing