Skip to content Skip to sidebar Skip to footer

How To Reload Javascript Code Block

I need to reload a block of javascript every amount of time.. say i need that block of any

Solution 1:

var frame;
setInterval(function() {
  frame = someSortOf.Code();
}, 15000);

That will execute the provided function every 15 seconds, setting your value. Note the var frame is declared outside the function, which gives it global scope and allows it to persist after your function executes.

You should not really "reload" a script. What you really want to do is simply run an already loaded script on a set interval.

Solution 2:

function foo() {
    // do something here

    if (needRepeat) {
        setTimeout(foo, 15000);
    }
}

setTimeout(foo, 15000);

Solution 3:

You can use setTimeout('function()', 15000); - put this line of code at the end of the function() so that it calls itself again after 15000ms.

The other way is just to call setInterval('function()', 15000); and this will call your function() every 15000ms.

The difference between the first and the second one is that the first calls the function after specific milliseconds (only once, so you need to insert it in the function itself) and the second one just calls the function every n milliseconds.

Post a Comment for "How To Reload Javascript Code Block"