Save Text File Button HTML


Is there a way to create txt file via html to be save on the user device to download or save.

So the way is to save the user information on the device rather than using webhooks to save it on a server then redirect the user to download the exported information file text

The code below can run on any browser and without the need to have any certain library

I tried the rich text but it didn’t work.
Any other ideas ?


<title>Javascript - Create Text file</title>
body {
font-family: Arial, Helvetica, sans-serif;

textarea {
font-family: Arial, Helvetica, sans-serif;
padding: 5px;


<button type="button" id="btnSave" onclick="save()">SAVE</button>


function save() {
var data = "my information export";
var c = document.createElement("a"); = "user-text.txt";

var t = new Blob([data], {
type: "text/plain"
c.href = window.URL.createObjectURL(t);;


I’m not really sure I understand, but… maybe the Copy to Clipboard action might be what you are looking for?

Basically I need to export the information in a text file and this information will be data added to the code above

So once a user click on save button it will download a .txt file

Please check this video

So what would happen when a user clicks the button? Should a dialog open, asking them to choose a location to save the “file”?

Yes or download directly the file

This way to export the log in a txt file or share this txt file later