DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
artydev
artydev

Posted on

Save content directly from browser

Sometimes you want to save content, a text for example directly from the browser, without talking to a server.

Here I use the nice library FileSaver

<textarea id="notes" style="width:300px; height: 100px;">
Content
</textarea>
<br />
<button onclick="saveContent()">
  Save
</button>

<script>
  function saveContent () {
    let data = notes.value
    var blob = new Blob([data], {type: "text/plain;charset=utf-8"});
    var name = prompt("Save file under")
      if (name != "" ) {
        saveAs(blob, name)         
      }
}
</script>

You can test it here SaveContent

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Good news! You can update to dark mode in your DEV settings.