0

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.

roh_dev
  • 275
  • 2
  • 6
  • 17

1 Answers1

2

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
}
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320