0
我想在html中設置一個計數器。默認情況下,瀏覽器對話框如警報,關閉警告等可防止計數器執行。我如何防止這種情況發生?我的代碼是一些什麼樣的下面如何防止瀏覽器對話框阻止用戶界面定時器
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>