'unload event issue in chrome and Firefox
I tried to use unload event, but it seems NOT work in Chrome or Firefox. So I tried another way, the issue is the pagehide callback seems never invoke:
if ("onpagehide" in window) {
window.addEventListener("pageshow", function(){alert("enter page")}, false);
window.addEventListener("pagehide", function(){alert("leave page")}, false);
} else {//for IE
window.addEventListener("load", function(){alert("enter page")}, false);
window.addEventListener("unload", function(){alert("leave page")}, false);
}
Solution 1:[1]
I'm not sure about Firefox but Chrome will ignore any alerts called from window.onunload. It will also not let you change any part of the URL, and possibly other things. That may be why it looks like the event isn't firing. To check whether it's firing you can return a string from the handler function, which brings up one of those "Are you sure you want to leave this page?" message boxes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gus |
