JavaScript
allows you to execute some code after specific amount of time. The timing
events allow you to do that. Using timing events you can execute loops
again and again after some time interval or perform a number of other
such tasks. These events also add security to your code by logging out
the users if they did not interact with the server for a specific duration.
This is mainly use in secure websites such as banking web sites where
crucial money transactions take place. The timing events are setTimeout(),
clearTimeout(), setInterval(), clearInterval()
Syntax
Functions |
Syntax |
setTimeout |
var
time = set Timeout ("Expression", delay time); |
setInterval |
var
time = setInterval ( function( ), delay time); |
clearInterval |
clearInterval(intervalID); |
clearTimeout |
clearTimeout
( timeoutId ); |
Example
<script
type = "text/javascript">
<!--
setTimeout
var
timeoutID = setTimeout(" alert ('Time out, Fifty seconds over');
", 50000);
var
intervalID = setInterval(" alert ('Time out, Fifty seconds over');
", 50000);
clearTimeout(timeoutID);
clearInterval(intervalID);
//-->
</script> |
|