Programming Tutorials

Pause execution in JavaScript

By: Dave Reed in Javascript Tutorials on 2011-01-28  

This javascript pauses the execution for specifed numSeconds.
function pause(numSeconds)
// Assumes: numSeconds >= 0
// Results: pauses execution for numSeconds seconds
{
    var now, goalTime;

    now = new Date();
    goalTime = now.getTime() + 1000*numSeconds;

    while (now.getTime() < goalTime) {
        now = new Date();
    }
}

  





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Javascript )

Latest Articles (in Javascript)