-
-
Save jesgundy/e53c122a12dbf09661dd996338f3487e to your computer and use it in GitHub Desktop.
Client-side Autosave Using localStorage
This file contains 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
// Retrieve the object from storage onReady | |
var autosave = localStorage.getItem('file'); | |
// parses the string (btw. its UTF-8) | |
var text = JSON.parse(autosave); | |
//modifies the textarea with the id="inputTextArea" | |
$("textarea#inputTextArea").val(text); | |
// Autosave on keystroke works in offline mode | |
$("textarea#inputTextArea").change(function(){ | |
// pulls the value from the textarea | |
var file = $('textarea#inputTextArea').val(); | |
// sets the file string to hold the data | |
localStorage.setItem('file', JSON.stringify(file)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment