JGC
JGC

Reputation: 12997

JavaScript causing "A script on this page may be busy, or it may have stopped responding." error in Firefox

I wrote a page by javascript that has over 1000 lines of code and so the page is so heavy. when i run the page on the firefox, it tell me that:

A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.

Script: http://localhost:5070/resources/ir.pnusn.branch.ui.pages.BranchMap/scripts/MapAddress.js:151

and I have in MyAddress.js:151:

function fillAddress(number)
{
150:    var filedNum=0;
151:    while(document.getElementById("choice4")!=null)
        document.getElementById("choice4").click();
    nextId=1;
    for(i=0;;i++)
    {
        var cookieChoiceName=number+"-"+filedNum+"-0";
        var cookieChoiceValue=getCookie(cookieChoiceName);
        if(cookieChoiceValue==null)
        {
            //alert(document.getElementById("choice4"));
            break;
        }
        var cookieFieldName=number+"-"+filedNum+"-1";
        var cookieFieldValue=getCookie(cookieFieldName);
        if(cookieFieldValue==null)
        {
            alert(document.getElementById("choice4"));
            break;
        }
        if(cookieChoiceValue!= "-1" && cookieChoiceValue!="-2" && document.getElementById("choice"+cookieChoiceValue)!=null)
        {
            document.getElementById("choice"+cookieChoiceValue).click();
        }
        var value=utf8_decode(unescape(cookieFieldValue));
        var finalval=replacePluse(value);
        // var Resvalue=value.substr(1,value.length-1);
        document.getElementById("txt"+(filedNum-1)).value=finalval;
        filedNum++;
    }
}

and when I press continue in warning window the code work correctly. but when i increase dom.max_script_run_time in firefox configuration file it does not change and after that when I press continue again it works. What's the problem?If you want more information about the code tell me to put for you here.

Upvotes: 1

Views: 2861

Answers (3)

Stephen C
Stephen C

Reputation: 718886

This line looks suspiciously like a infinite loop to me:

while(document.getElementById("choice4")!=null)
    document.getElementById("choice4").click();

Upvotes: 2

RaYell
RaYell

Reputation: 70414

Your while probably is an infinite loop. The condition you are using will always be true as long as you have element with id #choise4 present. Since you are not removing this element inside the loop, then it will never finish.

Upvotes: 2

Greg
Greg

Reputation: 321678

From your code it looks like the onclick function for 'choice4' is supposed to remove the element but isn't doing.

I'd check for a bug in that onclick.

Upvotes: 1

Related Questions