I need to call a Javascript
function when user closing the browser tab. The problem is I want to happen this only when user closing the browser. No need to happen for page refresh, link navigation,form submit and back button press. I have tried the below JQuery
code so far.
$(window).bind(
"beforeunload",
function() {
alert("don't close me");
return false;
}
)
$('form').submit(function() {
jQuery(window).unbind("beforeunload");
});
It's not working. Is there any other Javascript
tools than JQuery
available for this?
And if I call my function "beforeunload" event, above message is coming. I don't want to show this message and my function has to be worked. I tried by giving e.preventDefault. But it's not calling my function again. Can anybody suggest something.
Thanks.