简体   繁体   English

如何让我的页面只刷新一次?

[英]how can i make my page refresh only once?

Js: JS:

<script type="text/javascript">

function timedRefresh(timeoutPeriod) {

  var refreshed=true;

  if(refreshed){

    refreshed=false;

    setTimeout("location.reload();",timeoutPeriod);
  }

}
</script>

Html HTML

body onload="JavaScript:timedRefresh(5000);" body onload =“JavaScript:timedRefresh(5000);”

i can not get it to load only once its keeps reloading instead of taking the new value 我只能在它不断重新加载而不是获取新值时才能加载它

重新加载页面将再次触发加载事件,这将再次重新加载页面...您应该使用cookie或其他客户端数据存储来了解页面是否已加载一次。

You are making the assumption that the browser is keeping the javascript variable values between each page load, but everything is flushed. 您假设浏览器在每个页面加载之间保留javascript变量值,但所有内容都被刷新。 You might want to use HTML5 local storage so that state is persisted between pages. 您可能希望使用HTML5本地存储,以便在页面之间保持状态。

See http://www.w3schools.com/html/html5_webstorage.asp http://www.w3schools.com/html/html5_webstorage.asp

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

相关问题 我只希望页面刷新一次 - i want my page refresh only once 如何在每个页面刷新/加载时进行“循环一次”动画GIF背景播放? - How can I make a “loop once” animated GIF background play on every page refresh/load? 如何让我的实体在 A-Frame 的场景中只出现一次? - How can I make my entity appear only once in my scence on A-Frame? 为什么来自我的 api 的数据只显示一次,当我刷新页面时它会出错 - Why does data from my api only display once and when I refresh the page it gives an error 我的代码被复制并粘贴了大约 5 次,但我怎样才能让它只有一次? - My code is copy and pasted about 5 times but how can i make it so it's only once? 如何使此回调函数仅被调用一次? 在我的For循环之后 - How can I make this callback function only be called once? after my For loop 如何使用 IntersectionObserver 使我的框只出现一次? - How can I manage to make my boxes appear only once with IntersectionObserver? 如何让网页只显示一次? - How do I make a web page show up only once? 如何只刷新页面一次,以便可以将一些变量还原到页面上? - How to refresh page only once so you can restore some variables onto the page? 如何制作只能单击一次的元素? - How can i make a element that can be clicked only once?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM