I want to execute code every 10 seconds, but also on page load. I mean I want the code to execute when the page loads initially then every 10 seconds. The following code only executes the code initially after 10 seconds.
window.setInterval(function(){
/// call your function here
}, 10000);
Thanks!
You can do this :
(function(){
var f = function() {
// do something
};
window.setInterval(f, 10000);
f();
})();
The IIFE is used here to avoid polluting the enclosing namespace.
First execute the function in $.ready
and then start the interval with that same function.
Something along the lines of:
$(function() {
var f = function() { };
f();
window.setInterval(f, 10000);
});
Don't inline the function, and then just call it immediately:
window.setInterval(foo, 10000);
foo();
function foo()
{
//Do Stuff
}
I create LINK try this
functionCall();
function functionCall(){
window.setInterval(function(){
/// call your function here
}, 10000);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.