The advantage provided by PeriodicalExecuter is that it shields you against multiple parallel executions of the callback function.
Creating a PeriodicalExecuter
The constructor takes two arguments −- The callback function.
- The interval (in seconds) between executions.
Example
Following is the example which will pop up a dialogue box after every 5 seconds untill you will stop it by pressing "cancel' button.<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>
No comments:
Post a Comment