Javascript examples for Browser Object Model:Window setTimeout
The setTimeout() method calls a function or evaluates an expression after a number of milliseconds.
Parameter | Description |
---|---|
function | Required. The function that will be executed |
milliseconds | Optional. milliseconds to wait before executing the code. If omitted, the value 0 is used |
param1, param2, ... | Optional. Additional parameters to pass to the function |
A Number, representing the ID value of the timer that is set.
Use this value with the clearTimeout() method to cancel the timer
The following code shows how to Display an alert box after 3 seconds (3000 milliseconds):
<!DOCTYPE html> <html> <body> <button onclick="openWin()">Open "myWindow"</button> <script> function openWin() {/*from w w w .j a v a2 s . com*/ var myWindow = window.open("", "myWindow", "width=200, height=100"); myWindow.document.write("<p>This is 'myWindow'</p>"); setTimeout(function(){ myWindow.close() }, 3000); } </script> </body> </html>