Skip to content

Instantly share code, notes, and snippets.

@vladanyes
Created May 6, 2018 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladanyes/606e656e00f20d6fe3a12c06b207a45d to your computer and use it in GitHub Desktop.
Save vladanyes/606e656e00f20d6fe3a12c06b207a45d to your computer and use it in GitHub Desktop.
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