I've written a function to catch a loop after it has run over a specified time.
var t1 = new Date().getTime();
while(true){
//general code in here...
document.body.appendChild(document.createElement('div')); //This causes the problem
if(isInfinite(t1,3000)){
alert('Loop stopped after 3 seconds')
break;
}
}
function isInfinite(t1,timeLimit){
var t2 = new Date().getTime();
if(t2-t1> timeLimit){
return true;
}
else return false;
}
It works as expected, but when I try to append nodes to the document it fails to catch in chrome & safari. What's weird is it works when I have the debugger running, and it works in FF. What is causing this?