I found this Javascript sleep function here and it works in FF9, Chrome 14 (tested).
function sleep(ms) {
ms += new Date().getTime();
while (new Date() < ms){}
}
This function will block browser from doing anything, even setTimeout()
E.g.:
/*BEGIN*/
setTimeout(alert('stupid'), 1000);
sleep(2000);
// after sleep completed, setTimeout has its turn to run.
// The alert() will be shown after 3 seconds from /*BEGIN*/
This might be a stupid thing but sometimes you have to do stupid work and it’s required.
Advertisement