• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I trap browser window close

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic