• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to track browser close

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, does anyone know how to track when a browser closes. I want to perform a logoff function when the user closes the browser window by clicking X. In the logoff function I want to submit a form to invalidate the users session.
I have tried to use onUnload, but this occures everytime the url changes. I need to track only the close browser window.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GOOD LUCK
There is no way to really track the browser close.
Methods used are (IE only onbeforeunload)
Replace all links on a page with a javascript code that detects user is going to not be leaving....Mess
You have problems with back button and refresh
There is no way to do it, if you are logging out from the server, you have better luck timing it out.
If it is logged in by cookies, use a session cookie.
Eric
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Eric suggested, there is no real way to track this. However, I have figured a way out that currently works with my application. I have a hidden window that I use only for this purpose. When the user closes the browser window, that is the only way that this hidden window can be closed. When the unload method is called, i check a flag to see if the user has not exited cleanly already. If the user has not exit cleanly, the session is invalidated on the server using a modal window dialog.
hope this helps...
Maneesh
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic