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

Javascript examples for Browser Object Model:Window setTimeout

Description

Sleep for 4 seconds and close browser

Demo Code

ResultView the demo in separate window

<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>

Related Tutorials