MaximilianMairinger
MaximilianMairinger

Reputation: 2424

find out if last site was same as origin

I am using custom history manipulation on my onepage application (with history.pushState). As the user presses the browser native back button the site does not reload (thus not displaying the right content). I fixed this by listening for a window.onpopstate event where Id just reruning the initation script.

This however causes the user to be stuck on my page since as he tries to go back I simply reload the page, disreguarding if the page he wants to go to is on the same origin as mine or not. I would like somewhat like this:

window.onpopstate = () => {
  if (/*Site is same origin*/) load();
  else {
    //do Nothing
  }
};

How would I approch this?

Upvotes: 0

Views: 30

Answers (1)

trk
trk

Reputation: 2228

You could approach this using document.referrer, match it with your domain and then take action accordingly. More about this at MDN.

Upvotes: 1

Related Questions