I use the following two listeners on my page when a user closes a tab or window in chrome, but they don't seem to work
chrome.tabs.onRemoved.addListener(function (integer tabId, object removeInfo) {alert("Haooooo")});
chrome.windows.onRemoved.addListener(function (integer windowId) {alert("Haooooo")});
But the following function detects closing a window or closing a tab, but also starts when updating. Does anyone have a way to detect a browser / tab only for Chrome. I am not looking for this to work in any other browser. Finding a solution only in chrome
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "See you later" ;
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
}
);
source
share