Pause execution in JavaScript

By: Dave Reed Viewed: 153291 times  Printer Friendly Format    


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();
    }
}

  


Most Viewed Articles (in Javascript )

Latest Articles (in Javascript)

Comment on this tutorial