aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How can I trap browser window close 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 "How can I trap browser window close" Watch "How can I trap browser window close" New topic
Author

How can I trap browser window close

Srinivas
Greenhorn

Joined: Jun 07, 2002
Posts: 1
How can I trap browser window close event in javascrit. AS I am using sessions, want to logout session when the user closes the brwoser window..
I tried using onunload and onbeforeunload events but it didnt worked..
Could you please some one help me..
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
kurraram,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

onunload() should work. onbeforeunload() only works in IE. im not a js expert, but i will see if i can find some sample code for you.


SCJP
Visit my download page
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

this site might help you. it uses frames so i cant send you exact page. click on "handling events". near the bottom of that page they talk about capturing events
http://developer.netscape.com/docs/manuals/communicator/jsguide4/index.htm
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
My guess - you cannot.
I mean, your code will not be able to say, is this guy goes to another page, or closes hte window.
You should use reasonable value for session timeout in server settings.
You actually could try to use "onbeforeunload" to set some flag on a server side, and then if it is not reset in some amount of time, invalidate session, and all your pages will have hidden frame, and they will load into it some jsp for their "onload" event, and this jsp will reset this flag. So, page got "onbeforeunload", it set flag in a session, another page loads - it loads this hidden frame, wich reset value in a session.
But it doesn not sounds good even for me
 
jQuery in Action, 2nd edition
 
subject: How can I trap browser window close
 
Similar Threads
Tracking browser events in applet
How to disable mouse click on the MediaPlayer or Real Player
How to trap browser close button
How to close a window in GWT ?
Can I close a previously opened window?