Advertisement
stuppid_bot

Save data as file via JavaScript

Oct 11th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function saveFile(name, blob) {
  2.     var w = window;
  3.     var d = w.document;
  4.     var link = d.createElement('a');
  5.     link.setAttribute('download', name);
  6.     link.href = w.URL.createObjectURL(blob);
  7.     link.onclick = function () {
  8.         d.body.removeChild(this);
  9.     };
  10.     link.style.display = 'none';  
  11.     d.body.appendChild(link);
  12.     link.click();
  13. }
  14.  
  15. saveFile('hello.txt', new Blob(['Hello, world!']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement