JavaScript在几秒钟后刷新页面
我试图用JavaScript每18分钟刷新一次页面,但我的代码似乎不起作用 这是我的密码:JavaScript在几秒钟后刷新页面,javascript,html,setinterval,Javascript,Html,Setinterval,我试图用JavaScript每18分钟刷新一次页面,但我的代码似乎不起作用 这是我的密码: function startChecking() { secondsleft -= 1e3; if (secondsleft <= 3e4) { document.getElementById("div_countdown").style.display = ""; document.getElementById("timercounter").inn
function startChecking() {
secondsleft -= 1e3;
if (secondsleft <= 3e4) {
document.getElementById("div_countdown").style.display = "";
document.getElementById("timercounter").innerHTML = Math.abs(secondsleft / 1e3) + " Seconds"
}
}
function startschedule() {
clearInterval(timeout);
clearInterval(interval);
timeout = setTimeout("window.location.href=window.location.href;", threshold);
secondsleft = threshold;
interval = setInterval(function() {
startChecking()
}, 1e3)
}
function resetTimer() {
startschedule();
document.getElementById("div_countdown").style.display = "none";
document.getElementById("timercounter").innerHTML = ""
}
var timeout, interval;
var threshold = 108e4;
var secondsleft = threshold;
startschedule();
window.onload = function() {
startschedule()
}
<a id="div_countdown" style="display:none;" onclick="javascript:resetTimer();">Chat Will Refresh in <span id="timercounter"></span> Click <font color="#FA5882">here</font> to Cancel</a>
函数启动检查(){
第二个sleft-=1e3;
if(secondsleft唯一的更改是更短的延迟(不能等待18分钟来调试脚本)
在开始检查()
间隔也应为1000
剩下两个可定制的数字…
阈值
适用于您最长18分钟的时间…
以及在条件if(secondsleft用于清除超时使用clearTimeout
而不是clearInterval
:clearInterval(超时);
->clearTimeout(超时)中显示消息的时间量
没有得到它..在代码中创建一个间隔和超时。清除间隔时使用clearInterval
方法。清除超时时,应该使用clearTimeout
而不是clearInterval
。在startschedule
函数的第一行