xDisfigure

Create file download for any type file [ALL WEBBROWSER]

Oct 1st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function download (text, name, type) {
  2.                     type = !type ? 'text/plain' : type;
  3.  
  4.                     if(!text || !name) {
  5.                         console.warn('[Downloading File] Content and filename must be provided.');
  6.                         return false;
  7.                     }
  8.  
  9.                     var a = document.createElement('a');
  10.                     var file = new Blob([text], {type: type});
  11.  
  12.                     a.href = URL.createObjectURL(file);
  13.                     a.download = name;
  14.                     document.body.appendChild(a);
  15.                     a.click();
  16.                     document.body.removeChild(a);
  17.                 };
Add Comment
Please, Sign In to add comment