Friday, August 22, 2008

Javascript function similar to Sleep of JAVA

Here is a Javascript function that works similar to the Thread.sleep(milliseconds) method of JAVA.

The code of the JavaScript function is as under:

function pause(numberMillis)
{
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true)
{
now = new Date();
if (now.getTime() > exitTime)
return;
}
}

You need to call this function like
pause(1000) ;
to wait a second!

No comments: