Creating delays in javascript can be very essential under certain specific scenarios, though i would recommend you to avoid it in most cases.
The right way to create a delay would be by using setTimeOut method in javascript, as below:
setTimeout(“alert(‘hello world’)”,1500); // shows alertbox after 1500 milliseconds
The lazy way or to be precise – the naughty way, can be obtained from the below function:
<html>
<head>
<title>Javascript Pause</title><script language=”javascript”>
function pausejs(millis)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}
</script></head>
<body><form>
<input type=”button” value=”Push this button to pause the page scripts by 1500 milliseconds” onClick=”pausejs(1500);“>
</form></body>
</html>
Of course, this is a naughty equivalent to the pause method. But after all you can have a pause method in your javascript.
Very helpful JS pause example. Thankyou for sharing.