This chapter demonstrates about the Prototype.js Periodical Execution Which executes the function many times after the period of time and following are the concepts covered in this chapter.
Creating Periodical execution
Creating Periodical execution
Description
If user wants to execute function many times after certain period of time then user can use the Periodical Executor object and which provides shields instead of multiple parallel executions. User can create the periodical executor by taking the two arguments which are shown below.
Call Back Function
Interval Between execution
Once PeriodicalExecuter launched indefinitely the page will execute until stop() method executed. The code below demonstrates to generate the pop up box as shown below.
[jscript]
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function startExec() {
new PeriodicalExecuter(function(pe) {
if (!confirm('Want me to annoy you again later?'))
pe.stop();
}, 5);
}
</script>
</head>
<body>
<p>Click start button to start periodic executer:</p>
<br />
<br />
<input type = "button" value = "start" onclick = "startExec();"/>
</body>
</html>
[/jscript]
Result
By running the above code in a preferred browser user can get the following output as shown in below image.
Summary
Key Points
PeriodiacalExecutor executes until stop() executes.
User can set the time period for PeriodiacalExceutor.