Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
Created November 8, 2012 19:26
Show Gist options
  • Save ohpauleez/4040960 to your computer and use it in GitHub Desktop.
Save ohpauleez/4040960 to your computer and use it in GitHub Desktop.
Example of JSON import/export with localStorage
<html>
<head><title>Example of import/export for localstorage</title></head>
<body>
<h3 id="example-text">LS:...</h3>
</body>
<script>
var text = document.getElementById("example-text"),
storage_key = "hidden_ids",
json_str;
localStorage[storage_key] = [1, 2, 3, 4, 5];
json_str = JSON.stringify(localStorage[storage_key]);
text.innerHTML = json_str;
localStorage[storage_key] = JSON.parse(json_str);
text.innerHTML = localStorage[storage_key];
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment