I am trying to detect event when user are trying to close current tab or windows.I tried onbeforeunload and stack overflow answers. But no one worked for me. can any one help me to solve this. I followed this link to get answer but not worked for me. Below is the code which I tested on chrome.
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome
});
Thanks.