[英]Redirect to a page on manual page refresh using page refresh button or f5
I want to redirect user to Google whenever he clicks on the browser page refresh button or press the f5 key 我想在用户单击浏览器页面的刷新按钮或按f5键时将其重定向到Google
I write this code but it's not working fine: 我写了这段代码,但是不能正常工作:
window.onbeforeunload = function(){
location.href = '<?=$szLinkURL?>';
return 'are you sure you want to leave?';
}
I want that if I choose yes, then only I will be redirected, else stay in the same page. 我希望如果我选择“是”,那么只有我将被重定向,否则留在同一页面上。
Also, if only refresh button of the browser is clicked, then only the script will run; 另外,如果仅单击浏览器的刷新按钮,则仅脚本将运行;否则,仅运行脚本。 it won't run when the back button or forward button will be clicked. 单击后退按钮或前进按钮时,它将不会运行。
window.onbeforeunload = function(){
window.setTimeout(function () {
window.location =<?=$szLinkURL?>;}, 0);
window.onbeforeunload = null;
// necessary to prevent infinite loop, that kills your browser }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.