[Javascript] error calling the setTimeOut()

J. Lester Novros II lester at denhaag.org
Wed Jun 5 14:09:56 CDT 2002


Dear Murugan,

On 06/05/2002 05:30 PM, Selvaraj, Murugan (Indsys) wrote:
> It was working some time back. But now it is giving the error "STack over
> flow" 
> 
> I think the problem could be on calling the
> setTimeout('scriptOverlay('+s+')',3000);
> 
> While entering in to the else loop ,i am getting the above error.
> 
> Is there any problem in the setTimeOut() method?

Judging by the few code snippets that flew by, my guess would be that, since you 
don't do a 'clearTimeout()', you keep firing 'setTimeout's which probably cause 
the stack overflow at some point.

I would modify your code as follows:

    var runner;
    var running = false;

function scriptOverlay(serverPath)
{
    if (running)
       clearTimeout(runner);
    running = false;

    if (window.jVueLoaded)
    {
       alert('loaded');
       // more code...
    }
    else
    {
       runner = setTimeout('scriptOverlay(' + serverPath + ')', 3000);
       running = true;
       alert('not... loaded');
    }
}

This cancels a running timeout before firing a new one.

Hope this helps.

l8R lES
-- 
Sharing information with competitors can damage national security. [...] Some m$
code is so flawed it cannot be safely disclosed.
                         m$ vice president Jim Allchin in Federal Court testimony
http://open.denhaag.nu                                    http://www.denhaag.org




More information about the Javascript mailing list