I’m working on a proxy server checker and have the following code to start the requests at intervals of roughly 5 seconds using the setTimeout function;
function check() {
var url = document.getElementById('url').value;
var proxys = document.getElementById('proxys').value.replace(/\n/g,',');
var proxys = proxys.split(",");
for (proxy in proxys) {
var proxytimeout = proxy*5000;
t = setTimeout(doRequest, proxytimeout, url, proxys[proxy]);
}
}
However I can’t stop them once their started!
function stopcheck() {
clearTimeout(t);
}
A fix or better method will be more that appreciated.
Thank you Stack Overflow Community!
There are 2 major problems with your code:
tis overwritten for each timeout, losing the reference to the previous timeout each iteration.tis may not be a global variable, thusstopcheck()might not be able to “see”t.Updated functions:
Example of use: