简体   繁体   English

重定向到另一个页面(setTimeout)不会停止加载

[英]redirect to another page (setTimeout) won't stop loading

i use this script我用这个脚本

setTimeout(function(){
        window.location.href = '/MyPage';
     }, 5000);

it already redirect me,but never stop loading each 5 second, so how to redirect to (/MyPage) but after reach want to stay without loading它已经重定向了我,但永远不会停止每 5 秒加载一次,所以如何重定向到 (/MyPage) 但在到达之后想要保持不加载

I suppose that this script should redirect to itself.我想这个脚本应该重定向到自己。 Then you can set an entry in your local storage like:然后您可以在本地存储中设置一个条目,例如:

if (!localStorage.getItem('foo')) {
    localStorage.setItem('foo', '1');
    setTimeout(function(){
        window.location.href = '/MyPage';
    }, 5000);
}

If you want to reenable the redirect, you can delete the entry with:如果要重新启用重定向,可以使用以下命令删除条目:

localStorage.removeItem('foo');

Alternatively you can also set a cookie .或者,您也可以设置cookie

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

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