My requirement is to detect whether the browser is closed or refreshed or navigated(forward/back)
I am using window.onbeforeunload
but it triggers for every click (even buttons,links). To suppress that I used this code to prevent its call on button clicks
$(document).ready(function () {
$("input:submit").click(function () {
window.onbeforeunload = null;
});
$("input:image").click(function () {
window.onbeforeunload = null;
});
$('a:not(a[href^=javascript])').click(function () {
window.onbeforeunload = null;
});
});
But now I need to distinguish between browser close and navigation or refresh. How can I achieve it?
Edit
I am doing some logic in my window.onunload
event. For that I have a variable whose value needs to be assigned based on browser close/ navigation.