Sleep/Pause for specified number of seconds

 

Use the function below to do that. Function takes number of milliseconds to sleep as argument. So, if you want to pause execution of code for 2 seconds you'll pass 2000 (2 x 1000) as argument to this function.

function javascript_sleep(milliseconds)
{
 var date = new Date();
 var curDate = null;
 do
 { 
  curDate = new Date(); 
 }while(curDate - date < milliseconds);
}

Please feel free to use the comments form below if you have any questions or need more explanation on anything.

Tags

javascript,

Popular Searches

php, linux, mysql, ubuntu, mysql mysql, tools, install mysql, gearman, source code, java

more>>

Comments (write a comment):

0 comments so far. Be the first one to leave a comment on this article.

 

Comment