Auto Start download File using javascript and Jquery

 This is one of the simple concept to start download the particular file automatically without click any link. You can also set the timings, To download the file after some time. In Below example i given 2 seconds, So after two seconds it downloads the file automatically, You can set the time according to your choice. This will done by using simple javascript and jquery. Below is the full code and live demo. I hope this will useful.



Code for Auto download File using Jquery:

<html>
<head>
<title>Start Auto Download file</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(function() {
$('a[data-auto-download]').each(function(){
var $this = $(this);
setTimeout(function() {
window.location = $this.attr('href');
}, 2000);
});
});
</script>
</head>
<body>
<div class="wrapper">
<p>The download should start shortly. If it doesn't, click
<a data-auto-download href="auto-download.zip">here</a>.</p>
</div>
</body>
</html>

Post a Comment

2 Comments

  1. nice piece, thanks and continue with your great tuttorials

    ReplyDelete
  2. What do you add for it to open in a new window?

    ReplyDelete