roh_dev
roh_dev

Reputation: 305

redirect to an another web page on browser refresh

how to redirect to another web-page on browser refresh. I know people will say its a bad thing but it is quite necessary for me, so please ca you tell me how to redirect the user to another webpage on refresh.

Upvotes: 0

Views: 1332

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 370659

Check performance.navigation to see if the page has just been refreshed, and if it has, just assign to window.location.href accordingly:

if (performance.navigation.type === 1) {
  // page was just refreshed:
  window.location.href = 'https://some-redirect';
} else {
  // rest of your Javascript
}

Upvotes: 2

Related Questions