Javascript examples for Browser Object Model:Window setTimeout
Sleep for 4 seconds and close browser
<html> <head></head> <body> <a href="myfile.docx" id="myfile" name="fileToDownload">Download</a> <script> document.getElementById('myfile').click(); console.log(new Date()); sleep(4000);//wait for the file to finish downloading console.log(new Date()); window.close()//w ww . j av a2 s.co m function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { if ((new Date().getTime() - start) > milliseconds){ break; } } } </script> </body> </html>