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> 

Comments

Popular posts from this blog

Setup and implement simple angular.js program in MVC

Cross browsers detect print events using javascript

HTML5 drag and drop