Save Browser Text To A File And Download It
This is what I'm using to save text from a web page and download it to a file
HTML Source
notes
-
Replace the `"some text"`` in the Blob creation array with whatever should actually be downloaded. I'm pulling that from an `.innerText`` call in my live versions
-
I use `application/octet-stream`` to trigger the download from the browser. Using `text/plain`` instead would show the text in the browser window and let the user download manually from there
-
The filename of the download is set by changing `your-file-name.txt`` which can be set dynamically in the script
-
There's a `URL.revokeObjectURL(link.href)`` call that can be added after `link.click()`` to release the object. The documentation on it is a little unclear so I'm leaving it off
Reference
JavaScript Blob
MDN