How is it possible to identify that the browser's close button was clicked?
From the JavaScript Event Reference, the closest match appears to be the OnUnload event. However, this also catches navigation away from the page (and thus you don't want the functions to run if the user actually clicks on a link.)
There is no guarantee that the server will receive the message that the browser window is closed. For example, the older method that involved creating a small pop-up window would be blocked by most modern browsers. Using AJAX might work, but a browser window may close before it attempts to connect.
would this :
$(window).unload( function () { alert("Bye now!"); } );
help you ?
It is in jQuery though.
you should check the link given by Demoli though, it has further information about this particular method ( and its downside ).
edit : added link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With