Skip to Main Content
JavaScript: The Definitive Guide, Fourth Edition
book

JavaScript: The Definitive Guide, Fourth Edition

by David Flanagan
November 2001
Intermediate to advanced content levelIntermediate to advanced
936 pages
68h 43m
English
O'Reilly Media, Inc.
Content preview from JavaScript: The Definitive Guide, Fourth Edition

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 or func.

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript: A Beginner's Guide, Fourth Edition, 4th Edition

JavaScript: A Beginner's Guide, Fourth Edition, 4th Edition

John Pollock
Coding with JavaScript For Dummies

Coding with JavaScript For Dummies

Chris Minnick, Eva Holland

Publisher Resources

ISBN: 0596000480Supplemental ContentCatalog PageErrata