redirect to an another web page on browser refresh

2019-08-26 09:02发布

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.

1条回答
萌系小妹纸
2楼-- · 2019-08-26 09:30

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
}
查看更多
登录 后发表回答