Save Text File Button HTML

Hello

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 ?

<html>

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

textarea {
font-family: Arial, Helvetica, sans-serif;
padding: 5px;
}
</style>
</head>

<body>

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

<script>

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

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

</html>```

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