I need to call a method through ajax whenever the user try to close the browser or tab. From the docs I came to know that we can achieve this through window.onbeforeunload(chrome). But this is called whenever I click on back,forward buttons or by hitting the refresh button. Is there any possible way so that I can exclude these actions and trigger it only if the browser is closed.
Below is the code snippet I am using
window.onbeforeunload = function (event) {
var message = 'Important: Your will be logged out.';
if (event) {
$.ajax({
...
});
}
return message;
};