HTML5 provides download attribute that can be used in place of PHP-driven file download scripts. In this article, you will come to know about this new attribute of html5.
One Attribute, Two Functions
download attribute sets a file download name and the target name is different that actual link has.
<span><a href=abc.pdf" download=note.pdf">Download here</a></span>
It can also download the images instead of navigating to the file.
<span><a href=imgname.jpg" download /a></span>
Downloading Multiple Files with One Click
If you want to give the user this option of downloading page of images by clicking on "Download All" link. Here is the example:
<span><a href="http://www.robgravelle.com/images/35333443.jpg" download="rob1.jpg" class="download_file"><img src="http://www.robgravelle.com/images/35333443.jpg"></a>
<a href="http://www.robgravelle.com/images/765443.jpg" download="rob2.jpg" class="download_file"><img src="http://www.robgravelle.com/images/765443.jpg"></a>
<a href="http://www.robgravelle.com/images/899755444.jpg" download="rob3.jpg" class="download_file"><img src="http://www.robgravelle.com/images/899755444.jpg"></a>
<br><br>
<a id="downloadAll" href="#">Download All Images</a></span>
<span>$(document).ready(function() {
$('#downloadAll').click(function() {
$('a.download_file > img').each(function() {
$(this).trigger( "click" );
});
return false; //cancel navigation
});
});</span>
0 Comment(s)