RK Infotech
RK Infotech

Reputation: 45

Get events for browser action

I want to event when

How can I do that?

Thank you in advance.

Upvotes: 0

Views: 283

Answers (1)

GibboK
GibboK

Reputation: 73938

For reload and refresh use:

  1. window.onbeforeunload (calls on Browser/tab Close & Page Load)

  2. window.onload (calls on Page Load)

  3. 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

Related Questions