[Windows Object]
Definition and Usage
The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.
Tip: 1000 ms = 1 second.
Syntax
setTimeout(code,millisec,lang) |
Parameter | Description |
---|---|
code | Required. A reference to the function or the code to be executed |
millisec | Required. The number of milliseconds to wait before executing the code |
lang | Optional. The scripting language: JScript | VBScript | JavaScript |
Example
Display an alert box after 3 seconds:
<html> <head> <script type="text/javascript"> function timedMsg() { var t=setTimeout("alert('I am displayed after 3 seconds!')",3000) } </script> </head> <body> <form> <input type="button" value="Display timed alertbox!" onclick="timedMsg()" /> </form> </body> </html> |