Prototype Tutorial
Prototype Useful Resources
Selected Reading
- Prototype - Periodical Execution
- Prototype - Expressing Ranges
- Prototype - AJAX Support
- Prototype - JSON Support
- Prototype - Form Management
- Prototype - Event Handling
- Prototype - Enumerating
- Prototype - Templating
- Prototype - Basic Object
- Prototype - Hash processing
- Prototype - Array Processing
- Prototype - Strings Processing
- Prototype - Number Processing
- Prototype - Element Object
- Prototype - Utility Methods
- Prototype - Useful Features
- Prototype - Short Overview
- Prototype - Home
Prototype Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Prototype - Periodical Execution
Prototype - Periodical Execution
Many times it is required to execute a function many times after a certain period of time. For example, you may want to refresh your screen after a given time. Prototype provides a simple mechanism to implement it using PeriodicalExecuter object.
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.
Once launched, a PeriodicalExecuter triggers indefinitely, until the page unloads or the executer is stopped using stop() method.
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>Cpck start button to start periodic executer:</p> <br /> <br /> <input type = "button" value = "start" oncpck = "startExec();"/> </body> </html>