Name

setTimeout( ) — NN 2 IE 3 DOM n/a

Synopsis

setTimeout(expression, msecs[, args | language])

Starts a one-time timer that invokes the expression after a delay of msecs. Other scripts can run while the browser waits to invoke the expression. This method returns an ID that should be saved as a global variable and be available as the parameter for the clearTimeout( ) method to stop the timer before it expires and invokes the expression.

Navigator and Internet Explorer diverge in the use of the third parameter. Navigator lets you pass one or more parameters (as a comma-delimited list in a string) for the function acting as the expression parameter. Internet Explorer lets you specify the scripting language of the expression (if it is not the default JavaScript).

The setTimeout( ) method can be made to behave like the setInterval( ) method in some constructions. If you place a setTimeout( ) method as the last statement of a function and direct the method to invoke the very same function, you can create looping execution with a timed delay between executions. This is how earlier browsers (before the setInterval( ) method was available) scripted repetitive tasks, such as displaying updated digital clock displays in form fields or the status bar.

Returned Value

Integer acting as an identifier.

Parameters

expression

Any script expression as a string, but most commonly a function. The function name with parentheses is placed inside the parameter’s quoted string.

msecs

The time in milliseconds ...

Get Dynamic HTML: The Definitive Reference 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.