【发布时间】:2013-05-28 14:45:31
【问题描述】:
我的代码中有函数,假设按下按钮时页面的刷新时间从 50 秒逐渐减少到 10 秒。这里是:
<div id="signin" onclick="pgeReload()"></div>
....
<script type="text/javascript">
var count=0;
function pgeReload(){
if(count <= 4){
count++;
}
var times = count*10000;
var pospond = 50000-count;
setTimeout(function(){window.location.reload()}, pospond);
}
</script>
我的问题是页面的重新加载总是在 50 秒后发生,因为(如果我理解正确的话)变量 count 在页面重新加载时总是重新分配为 0。
我的问题是,即使在页面刷新后,计数值增加后,我还能保留它吗?
非常感谢所有可以帮助我的人。
带有html5的版本。但是,问题仍然是初始值。计数始终为 0
<script type="text/javascript">
var count=0;
function pagereload(){
if(typeof(Storage)!=="undefined")
{
count++;
window.content.localStorage[key]=count;
var tempTime = parseInt(window.content.localStorage[key])*1000;
var pospond = 50000-tempTime;
setTimeout(function(){window.location.reload()}, pospond);
}
else{
setTimeout(function(){window.location.reload()}, 30000);
}
</script>
【问题讨论】:
-
您可能会受益于使用 html5 会话存储
-
在这个特定的例子中如何使用它?
-
如果您在新标签页中打开同一页面会怎样?
标签: javascript