The customized Sleep way :
setTimeout("alert ('called from setTimeout()');",4000);
Difference between setTimeout and sleep()
The difference between the above function is that sleep will halt the script and will not allow the script to execute further lines of code. However when setTimeout is called, it won’t halt the further execution of the script, instead it will execute after the specified interval of time and also the other functions (if any) will keep on executing.
if you want to check this scenario .. just copy paste the below code into the body section and comment, sleep and setTimeout function calls one by one to notice the difference.
<script>// <![CDATA[ //sleep(4000); setTimeout("alert ('called from setTimeout()');",4000); alert("we are done"); // ]]></script>
Hope this helps.