What I want to do is, to fire some function, only when user tries to close browser window by clciking on x button. But not on refresh, “back” button click events like following function does.
$(window).unload( function () { alert("Bye now!"); } );
So is there any way to achieve this? Thx in advance
you could try forcing the user to a default location hash of #default as soon as they load the page. Then, if the person navigates back with the back button you can detect this with either a timer or the window’s “popstate” event. Then, you could do something at this point like send them to another url.
In this way you could detect a window CLOSE with the “onbeforeunload” event and a back button press with the method mentioned in the last paragraph. Messy but it works.