【发布时间】:2015-06-25 11:03:25
【问题描述】:
我想在 html 中设置一个计数器。默认情况下,警告、关闭警告等浏览器对话框会阻止计数器执行。我该如何防止呢?我的代码有点像下面给出的 sn-p:
var count = 30;
var counter = setInterval(timer, 1000);
function timer() {
count = count - 1;
if (count <= 0) {
clearInterval(counter);
return;
}
document.getElementById("timer").innerHTML = count + " secs";
}
window.onbeforeunload = function() {
return "I am blocking counter"
}
<span id="timer">...</span>
<button type="button" name="name" value="caption" onclick="alert('block this')">block counter</button>
【问题讨论】:
标签: javascript html multithreading dom-events counter