Advertisement
rgruber

javascript download generated file

Apr 17th, 2025
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.35 KB | Source Code | 0 0
  1. function download1(content, fileName) {
  2.   const blob = new Blob([content], { type: 'text/plain' });
  3.   const url = URL.createObjectURL(blob);
  4.   const a = document.createElement('a');
  5.   a.href = url;
  6.   a.download = fileName || 'download.txt';
  7.   document.body.appendChild(a);
  8.   a.click();
  9.   document.body.removeChild(a);
  10.   URL.revokeObjectURL(url);
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement