DEV Community

artydev
artydev

Posted on

Download attribute

Here is another way to download stuff created dynamically using "download" attribute

<a download="hello.txt" href='#' id="link">Download</a>

<script>
  let blob = new Blob(["Hello, world!"], {type: 'text/plain'});
  link.setAttribute("download", link.getAttribute("download"))
  link.href = URL.createObjectURL(blob);
</script>

You can test it here : ForceDownload

Top comments (0)