IE and setTimeout
Javascript today is a must have if you want you web pages change hover time without the need to full reload it. Changes over time in web pages generaly refers to asynchronous server requests (or AJAX requests) but this changes can be to the HTML elements or their properties.
To do this last option we can use the setTimeout function, it definition is:
setTimeout(functionName, time, parm1, parm2, ... , parmN);
This function call the functionName after the time milliseconds of the call, and pass the parm1, parm2 … parmN to functionName. Well this will work like I said with the exception of the Microsoft browser, in this browser you can’t pass the parameters to functionName.
See the following code:
function addXTimes(val, times) {
if (times==0) {
alert(0);
} else if (times-2>0) {
setTimeout(addXTimes, 500, val+val, times-1);
} else {
alert (val);
}
}
setTimeout(addXTimes, 500, 2, 6);
In most of the browsers this wil work perfectly, but on IE it does not work at all because the setTimeout function only accepts 2 parameters.
The solution for this problem is calling addXTimes inside an anonymous function that is called from setTimeout. See the next code with a solution:
function addXTimes(val, times) {
if (times==0) {
alert(0);
} else if (times-2>0) {
setTimeout(function() { addXTimes(val+val, times-1); }, 500);
} else {
alert (val);
}
}
setTimeout(function() { addXTimes(2,6); }, 500);
—
Links of interest:
http://www.dmuth.org/node/1252


