JavaScript - Handle Browser Close Event? - Asked By avula on 03-May-13 05:40 AM


Hi Every one,

Could you please suggest me how to solve handle browser close event..?

actually i have used unload,onunload,onbeforeunload events in jquery but all events called in page refresh (F5)..
but i dont want to close my browser window in page refresh(f5)..

please suggest me..
Thank you..
Robbe Morris replied to avula on 03-May-13 08:26 AM
Most modern versions of browsers will not accurately and reliably trigger this event.  Especially in a manner that you can react to it.  Done for security reasons.
Erik Little replied to avula on 28-Feb-14 02:41 PM
This would be an awesome feature for browsers to be able to offer.

Really the only way to know if the user still has the browser window open is to set an interval and ping the server ever so often, when the pinging stops do what ever it is you need to do on the server side.

If you do not need to do something on the server when the client closes the browser, then there really is no real reason to be notified. It would be nice, but not something that is really necessary.