Sleep for 4 seconds and close browser - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setTimeout


Sleep for 4 seconds and close browser

Demo Code

ResultView the demo in separate window

      <a href="myfile.docx" id="myfile" name="fileToDownload">Download</a> 
console.log(new Date());

sleep(4000);//wait for the file to finish downloading
console.log(new Date());
window.close()//w ww  .  j av a2  m

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){


Related Tutorials