• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Creating Timed Events

On occasion, it can be useful to have the browser call your code at a later time, as when you want to display scrolling text in the status bar or display a clock. JavaScript gives you two ways to do this—using the setInterval/clearInterval methods and the setTimeout/clearTimeout methods.

You use setInterval to set the interval (measured in milliseconds, 1/1000ths of a second) between repeated calls to your code and setTimeout to set a length of time after which the browser will call your code. That is, setInterval is designed to be used for repeated calls, and setTimeout just for a single call sometime in the future. In practice, however, setTimeout, which was introduced before setInterval, is often used for repeated calls as well.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint