page doesn't stop loading – javascript
Question by Lan
what does it mean if the twirly thing in the tab of the page wont stop spinning, ie saying its loading?
i have a php for loop and in each one of these it throws out i have a javascript onload function with a for loop looking to see if that id (from mysql) is in the javascript cookie array.
hope that makes sense. it all works fine but wont stop loading.
anyway, i’ve played around with break and return false which stop the loading but then doesnt give me the results i want.
can anyone point me in the right direction?
thanks
this is the javascript function that is being called by an onload in the img tag that each loop created by the php for function is throwing out.
n is the id. secondarray is the cookie data put into a readable array.
function cookietest(n)
{
for (i = 0; i < secondarray.length; i++)
{
if (secondarray[i] == "ca[]="+n ) document.getElementById(n).src = "saved.png" ;
}
}
Answer by Starx
Checking length inside a loop is always a killer. And breaking out of a loop at certain point, helps you improve the performance too.
function cookietest(n)
{
var l = secondarray.length;
for (i = 0; i < l i++)
{
if (secondarray[i] == "ca[]="+n ) {
document.getElementById(n).src = "saved.png" ;
break; //break out of loop it is no longer needed I GUESS
}
}
}
P.S: I am just answering based on the codes OP provided, the culprit could be others as well.