Download a file using javascript
When we want to download a file from client side code below java script code is very use full. Any format files like images, pdf, doc etc,. download through below code.
JAVASCRIPT CODE :
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
}
HTML CODE :
<a class="apdfExport" onclick="downloadURI('http://lh5.googleusercontent.com/-pi_poyLdiyg/AAAAAAAAAAI/AAAAAAAAABg/pFFFk0Hc3ok/s80-c/photo.jpg','test')">Download file</a>
JAVASCRIPT CODE :
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
}
HTML CODE :
<a class="apdfExport" onclick="downloadURI('http://lh5.googleusercontent.com/-pi_poyLdiyg/AAAAAAAAAAI/AAAAAAAAABg/pFFFk0Hc3ok/s80-c/photo.jpg','test')">Download file</a>
Comments
Post a Comment