简体   繁体   English

重定向到浏览器刷新按钮上的其他页面,请单击

[英]Redirect to different page on Browser Refresh Button Click

I want the user to be redirected to a different page on click of the browser refresh button but I am unable to do so. 我希望在单击浏览器刷新按钮后将用户重定向到其他页面,但我无法这样做。 I have tried using onbeforeunload but it does not seem to work for my requirement as it gives a message of Leave and Stay but even that does not seem to be working on chrome. 我曾尝试使用onbeforeunload,但它似乎无法满足我的要求,因为它给出了“离开并停留”的消息,但即使在chrome上似乎也不起作用。 So how can I redirect the user to a different page on click of browser refresh button. 因此,如何在单击浏览器刷新按钮时将用户重定向到其他页面。

The Code that I tried: 我尝试过的代码:

<html>
<body>
<script>
window.onbeforeunload = function(e) {
  return 'Dialog text here.';
};
</script>
</body>
</html>

Regards, Rushabh 此致Rushabh

You have to check performance.getEntriesByType on page load . 您必须在页面加载时检查performance.getEntriesByType here is how you can try so . 这是您可以尝试的方法。

 function checkEvt(){ var evTypep=window.performance.getEntriesByType("navigation")[0].type; if (evTypep=='reload'){ window.location.replace("http://www.stackoverflow.com"); } } checkEvt(); 

You can try this: 您可以尝试以下方法:

  if (performance.navigation.type == 1) {
    location.href='https://www.google.com';
  } else {
    console.log( "Not reloaded");
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM