gpt4 book ai didi

javascript - setTimeout放置在 header 中,我如何限制运行1次

转载 作者:行者123 更新时间:2023-11-27 23:19:18 27 4
gpt4 key购买 nike

我怎样才能确保这不会再次执行。我将所有页面重定向到网站上的单个页面。它会不断刷新/重新加载该页面,因为脚本必须放置在标题中。

   setTimeout(function(){
window.location="mysite/page";
},1000);

最佳答案

刷新页面时,您可以向网址添加哈希:

<html>
<head>
<script type="text/javascript">
var loc = window.location.href;
if (loc.indexOf ("#DoNotRefresh") < 0) {
setTimeout(function(){
window.location="#DoNotRefresh";
},1000);
}
console.log(new Date());
</script>
</head>

关于javascript - setTimeout放置在 header 中,我如何限制运行1次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35525581/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com