function process(){
window.location.reload(false);
}
function looping(){
setTimeout(process(), 10000);
}
var looper = setInterval(looping(), 10000);
I'm trying to reload a page every 10 seconds, but the above code will too frequently reload the page. Why?
function process(){
window.location.reload(false);
}
function looping(){
setTimeout(process, 10000);
}
var looper = setInterval(looping, 10000);
try above code.
in your example, instead of providing a call back function to the setTimeout and setInterval, you were, just calling the callback function. just provide the function name and its fixed
UPDATE: Functions are first class objects in JS. you can pass it to a function, return a function from another function etc... so those things are done, by just using the function name(just the function name, like any other variable name).
invoking a function is done using the parenthesis, you were by mistake invoking the function, instead of passing the function to setTimeout
and you can get rid of the setTimeout completely and just do as shown below
function process(){
window.location.reload(false);
}
var looper = setInterval(process, 10000);