HTML DOM setInterval() Method
Complete Window Object Reference
Definition and Usage
The setInterval() method calls a function / evaluates an expression at specified
intervals (in milliseconds).
The setInterval() method will continue calling the function until clearInterval() is called or the window is
closed. The ID value returned by setInterval() is used as the parameter for the
clearInterval() method.
Syntax
setInterval(code,millisec[,"lang"])
|
Parameter |
Description |
code |
Required. A pointer to a function or the code to be executed |
millisec |
Required. The number of milliseconds |
lang |
Optional. JScript | VBScript | JavaScript |
Example
The following example calls the clock() function every 50 millisecond. It
also have a button to stop the clock:
<html>
<body>
<input type="text" id="clock" size="35" />
<script language=javascript>
var int=self.setInterval("clock()",50)
function clock()
{
var t=new Date()
document.getElementById("clock").value=t
}
</script>
</form>
<button onclick="int=window.clearInterval(int)">
Stop interval</button>
</body>
</html>
|
Try-It-Yourself Demos
Use
setInterval() and clearInterval()
Complete Window Object Reference
|