window.setTimeout or window.setInterval are pretty much your only friends.
An example of how to use setTimeout
to recursively call a function that sets another timeout is as follows
function go() {
if (go.count < 4) {
// logs 1, 2, 3 to firebug console at 1 second intervals
console.log(go.count++);
window.setTimeout(go, 1000);
}
}
go.count = 1;
go();
You may choose to capture the timeoutID to use with window.clearTimeout if you need to clear the timeout prior to it finishing.
Note that neither window.setTimeout nor window.setInterval block execution of other script - I don't believe that this is possible with JavaScript in it's current guise. There are ways that could be coded to mimic UI blocking, such as using showModalDialog
or having some global blocking
boolean which are about as near as you can get I'm afraid.