views:

419

answers:

3
var checkTextValue = setTimeout(function() {
var textVal = $('p').text();
if (textVal == 'expectedValue'){
    callback();
} else {
    setTimeout(arguments.callee, 10);
}
},10);

i have this code,it works just fine but the problem is that in firefox the page looks like is endlessly loading.

A: 

That is because it is endlessly loading. Basically you do recursion and start another instance every ten milliseconds. Given enough time, I think it also is possible to kill your browser with this code.

Try using an onchange-eventhandler on your input field instead.

Martin Hohenberg
I'm pretty sure it's every ten milliseconds, not seconds
Cameron
ok, but the function is called every ten milliseconds until the textVal gets the expected value. this is how i interpret this code...
kmunky
dang, you are correct...
Martin Hohenberg
A: 

I think its a case of recusrsion. Google 'recusrion' for more clues. Just kidding. checkTextValue will be running indefinitely unless the value is 'expectedValue'.

Igor Zevaka
+1  A: 

Looks kind of useless... I mean setTimeout(checkTextValue, 10); - what are you setting there? checkTextValue is just a timeout ID, nothing else... No idea why FF would load endlessly, simply because the code is faulty...

Jefim
this is a small scale version of my original script, i updated it (arguments.callee), and it really works...the only problem is that permanently loading status in FF
kmunky
var check = function () { console.log('chack'); setTimeout(chack, 1000); }check();This code perfectly works without this loading issue (the same thing oversimplified). So try it out. If it works - that means that you prolly need to increase the timeout itself.
Jefim
Btw, your code works in my FF 3.5.4pre Win. So, uhm... check your FF? :) No loading 'look-alike' symptoms.
Jefim