Prototype.js - SPLessons

Prototype.js Periodical Execution

Home > Lesson > Chapter 11
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Prototype.js Periodical Execution

Prototype.js Periodical Execution

shape Introduction

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

shape 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

shape Key Points

  • PeriodiacalExecutor executes until stop() executes.
  • User can set the time period for PeriodiacalExceutor.