Jump to content

setInterval()


jaymc

Recommended Posts

Is there a way to use setInterval() without it calling the function at the start, and then how ever many seconds later

 

So for instance this will execute do() every 10 seconds, however, when the page is loaded it wil lexecute then execute again 10 seconds later and so on. When the page is loaded I want it to load do() for the first time after 10 seconds...

 

setInterval(do(), 10000)

Link to comment
Share on other sites

mootools use setInterval too for their periodical function, you can do it using setTimeout instead and calling the function on load.

 

function do(){
     do something
     ....
     setTimeout("do()", 10000);
}

do();

 

That wouldnt work either

 

The problem is... its an AJAX refresh, however, when the page is first loaded I use PHP to include the file I want refreshing

 

From then on, I want javascript to recall the file ever 10 seconds..

 

The problem is.. when I use PHP to originally include the first load of the file.. the file is processed

 

Then, when the do(); kicks in from the javascript, ir immediately requests the file, and then again every 10 seconds

 

What I need the javascript to do is not do anything at all for 10 seconds, rather than do it when do() is called and then every 10 seconds..?

Link to comment
Share on other sites

mootools use setInterval too for their periodical function, you can do it using setTimeout instead and calling the function on load.

 

function do(){
     do something
     ....
     setTimeout("do()", 10000);
}

 

piggy backing off of this do

 

window.onload = function(){

setTimeOut('do();', 10000);

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.