Neurohazard
暮雲煙月,皓首窮經;森羅萬象,如是我聞。

禁用网页自动刷新

wpadmin~January 1, 2020 /Software Engineering

禁用网页自动刷新

正文

一般而言,网页的自动刷新,追根溯源都是由 setInterval(), setTimeout() 之类的函数实实现的。
这些定时器可以由 clearInterval(), clearTimeout() 来解除。

var maxId = setTimeout(function(){}, 0);
for(var i=0; i < maxId; i+=1) {
    clearTimeout(i);
}


function ClearAllTimers() {
    var maxId = setTimeout(function(){}, 0);
    for(var i=0; i < maxId; i+=1) {
        clearTimeout(i);
    }
}

function ClearAllNodeTimer() {
    var nodes = document.all;
    for(var i=0;i < nodes.length; i++){
        var o = nodes[i];
        clearInterval(o);
    }
}

参考资料

https://stackoverflow.com/questions/1896875/is-there-a-way-to-clear-all-javascript-timers-at-once
https://stackoverflow.com/a/8832353

Leave a Reply

Your email address will not be published. Required fields are marked *