• 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 to catch browser close event?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Well it's amazing to know that there is no way i can track the event of browser closing(IE-6, and when i say browser close it's either clicking on X button or Alt+F4 only {both of them together} and not page refresh of back/fwd buttons), and this statement comes after lot of R&D.
But still i feel there must be something by which javascript can do it?

Is there any one who can provide some code for that thing?

Thanks
Manoj
 
Author
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try capturing the window.onclose event or the document.onunload event. I've tried these before and have somewhat uneven results, so try it in your environment.
 
Manoj Amrutkar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can you provide some code please?

Thanks
Manoj
 
Ryan Asleson
Author
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something like this for the onunload event:

 
Manoj Amrutkar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
thanks, but as i allready mentioned in my first post that unload or onbeforeunload gets called on refresh and back/fwd buttons.
i have a chat application in which suppose user closes the browser without proper logout his session has to be expired and he will be removed from chat room's list(which is maintained in context, and that i will do with DWR in javascript).
but for that i need to catch that event isn't it?

Thanks
Manoj
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no way to really do it as you mentioned. You need to rely on the server's session to expire and dump the user. Not pretty, but that is all you really have.

Personally you can do some sort of think without session. If you do not get a response from the user (Ajax request to check for new data) than you know they are gone and dump them.

Eric
 
reply
    Bookmark Topic Watch Topic
  • New Topic