I want a javascript
code snippet which will detect while closing the tab or closing the browser and should not activate event when go to other link or download any file any idea ? I saw there are lot of threads but didn't get the solution i tried this
a)
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome
});
b)
window.onbeforeunload = function () {
return "Do you really want to close?";
};
but its breaking other functionality(downloading file on click of anchor). I shouldn't be triggered when browser get refresh or opening link or downloading any file.Any Idea on this?