W3Schools.com

Window setTimeout() Method

Window Object Reference Window 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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The setTimeout() method is supported in all major browsers.


Example

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>

Try it yourself »


Examples

More Examples

Display a timed text

Count forever - with a Stop button

A clock created with timing events


Window Object Reference Window Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE