Posted By

jakob101 on 07/29/14


Tagged

iframe javascript file download


Versions (?)

Download file using javascript


 / Published in: JavaScript
 

Uses javascript to create a hidden iframe which downloads the file

  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  

You need to login to post a comment.