Created
July 20, 2021 14:27
-
-
Save FloStar3000/880a1f214849a3846021428ba7631994 to your computer and use it in GitHub Desktop.
Download Text as File in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const element = document.createElement('a'); | |
const file = new Blob([text], { type: 'text/plain' }); | |
element.href = URL.createObjectURL(file); | |
element.download = `${filename}.txt`; | |
document.body.appendChild(element); | |
element.click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment