Using Prototype.js and PeriodicalExecuter
Filed Under (Lessons, Tutorials) by admin on 15-02-2006
This quick tutorial will show you how to get started using prototype’s PeriodicalExecuter object. This object is useful for for when you have to repeat a function with a set interval. We will make a simple application that will alert the user an incremented message every 5 seconds.
Here is the code:
[code]
var i = 0;
function showMsg () {
alert(i);
i++;
}
new PeriodicalExecuter(showMsg, 5);
[/code]
The first parameter the object takes is the function name (with no parameters) and secondly the interval of time in seconds. We will be exploring this object more in our upcoming workshop.










Using Prototype.js and PeriodicalExecuter
Use PeriodicalExecuter to execute a method every x seconds.
I wonder if its any different than window.setTimeout(’runMoreCode()’, timeInMilliseconds);
…
Thank you for your site. I have found here much useful information…-pharma
Hi,
I am building a new site in Hebrew using prototype.js
Everything works fine, but not the
new Ajax.Request(’./nextPage.php’, {method:’post’,….
In nextPage.php I get strange character although I added
header(’Content-Type: text/html; charset=WINDOWS-1255′); in the start of the PHP.
Do you know if and how I can specify the Ajax.Request to use charset=WINDOWS-1255?
Thanks and Best regards,
Eylon
The site which I am building: http://www.yaldut.com
You have a great website. Keep up the good work.
Hi,
Thank you, your code was really helpfull i made a variation but i will improve it, making it more generic.
var i = 0;
function changeImage() {
if(i%2==0){
new Effect.Fade(’image1′, { // the id of the image1 containing the photos
duration: 1,
fps: 50,
afterFinish: function() { new Effect.Appear(’image2′, {duration: 1, fps: 50, queue:’end’})}
});
}else{
new Effect.Fade(’image2′, { // the id of the image2 containing the photos
duration: 1,
fps: 50,
afterFinish: function() { new Effect.Appear(’image1′, {duration: 1, fps: 50, queue:’end’})}
});
}
i++;
}
window.onload = new PeriodicalExecuter(changeImage, 10);