Using timeouts in Javascript enables a preset
delay to be set before a piece of code actions. for example we could
have a layer revealed when the page loads, which after a predefined
time disappears. Whilst a timeout is active the browser will continue
to do other things. However, once the timeout comes to an end the
browser will act on the code specified.
A timeout is started with the setTimeout() method. This
method takes two parameters, the first is a statement which may be a
group of statements. This is enclosed in quotes. The second
parameter is the duration of the wait, as this is an integer (multiples
or thousands of a second) it is not enclosed in quotes.
For example:
doIt = window.setTimeout(hideLayer('helpLayer',10000)
The variable doIt is used as an identifier for our timeout, this enables us to have more than one timeout active at a time.
| This article viewed: 1480 times | Back |
Copyright © 2004-2007 Janet Systems Ltd.