AlexanderNorup

DownloadScript Js

Aug 12th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function download(filename, text) {
  2.   var element = document.createElement('a');
  3.   element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  4.   element.setAttribute('download', filename);
  5.  
  6.   element.style.display = 'none';
  7.   document.body.appendChild(element);
  8.  
  9.   element.click();
  10.  
  11.   document.body.removeChild(element);
  12. }
Add Comment
Please, Sign In to add comment