Hi,
I'm trying to write a web app that uses Javascript to perform a fairly complex calculation (involves factorials and Bessel functions). When I run the script in IE, it gives me a warning that the script is unresponsive or taking a long time, and asks if I want to continue running it. I've read that to get around this, you can use either the setTimeout or setInterval commands to essentially reset the counter that IE uses to determine if a script is long-running.
I've tried implementing this, but have not succeeded. When I run a profiler, it appears that my function which computes a factorial is what takes most of the time, so I'd like to use setTimeout in that function. Here's the function I currently have:
function factorial(x) {
var buff = 1;
for (i=x;i>=1;i--) {
buff = buff * i;
}
return buff
}
I've tried replacing the code with something like this, but it isn't working properly:
function factorial(x) {
if (x==0) {
factbuff=1;
}
else {
factbuff = x;
factidx = x;
setTimeout('dofact()',50);
}
return factbuff
}
function dofact() {
if (factidx > 1) {
factidx--;
factbuff = factbuff * factidx;
}
}
Anybody know what I'm doing wrong and how I can correctly implement the setTimeout function in order to calculate a factorial while eliminating the script warning in IE?