Reputation: 45
I want to event when
How can I do that?
Thank you in advance.
Upvotes: 0
Views: 283
Reputation: 73938
For reload and refresh use:
window.onbeforeunload (calls on Browser/tab Close & Page Load)
window.onload (calls on Page Load)
window.onunload (unloading its content and resources)
But a better way to know that the page is actually reloaded is to use the HTML 5 navigation time API.
// check for navigation time API support
if (window.performance) {
console.log("window.performance work's fine on this browser");
}
if (performance.navigation.type == 1) {
console.log( "This page is reloaded" );
} else {
console.log( "This page is not reloaded");
}
For back and forward button go with HTML5 demo
window.addEventListener("popstate", function(e) {
// if a back or forward button is clicked
// do whatever
});
Upvotes: 1