Download file using javascript


/ Published in: JavaScript
Save to your folder(s)

Uses javascript to create a hidden iframe which downloads the file


Copy this code and paste it in your HTML
  1. var downloadURL = function downloadURL(url) {
  2. var hiddenIFrameID = 'hiddenDownloader',
  3. iframe = document.getElementById(hiddenIFrameID);
  4. if (iframe === null) {
  5. iframe = document.createElement('iframe');
  6. iframe.id = hiddenIFrameID;
  7. iframe.style.display = 'none';
  8. document.body.appendChild(iframe);
  9. }
  10. iframe.src = url;
  11. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.