Created
January 10, 2016 16:42
-
-
Save xto3na/f0f2b79a52a1983fdb30 to your computer and use it in GitHub Desktop.
AutoSave in localStorage
This file contains hidden or 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
if (window.localStorage) { | |
var elements = document.querySelectorAll('[name]'); | |
for (var i = 0, length = elements.length; i < length; i++) { | |
(function(element) { | |
var name = element.getAttribute('name'); | |
element.value = localStorage.getItem(name) || ''; | |
element.onkeyup = function() { | |
localStorage.setItem(name, element.value); | |
}; | |
})(elements[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment