Name
Window.setInterval( ) — periodically execute specified code
Availability
JavaScript 1.2; IE 4 supports only one of the two forms
Synopsis
window
.setInterval(code
,interval
)window
.setInterval(func
,interval
,args...
)
Arguments
-
code
A string of JavaScript code to be periodically executed. If this string contains multiple statements, they must be separated from each other by semicolons.
-
func
A JavaScript function to be periodically executed. This form of the method is not available in IE 4.
-
interval
An integer that specifies the interval, in milliseconds, between invocations of
code
orfunc
.-
args...
Any number of arbitrary values to be passed as arguments to each invocation of
func
.
Returns
A value that can be passed to Window.clearInterval( )
to cancel the periodic execution of
code
or func
.
Description
setInterval( )
repeatedly executes the JavaScript
statements specified in the string code
,
at intervals of interval
milliseconds.
In Netscape 4, but not IE 4, a function may be passed as the first
argument instead of a string. In this form of setInterval( )
, the specified function, func
,
is repeatedly invoked, at intervals of
interval
milliseconds. Any additional
argument values, args
, passed to
setInterval( )
are passed as arguments to each
invocation of func( )
.
In both forms, the setInterval( )
method returns a
value that can later be passed to Window.clearInterval( )
to stop code
or
func
from being repeatedly executed.
setInterval( )
is related to setTimeout( )
. Use
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.