I searched for this question in various places, but all that they mention is the use of javascript window.unload & window.onbeforeunload. Also it doesn\'t
$(window).unload(function() { alert('Handler for .unload() called.'); });