Created
November 8, 2012 19:26
-
-
Save ohpauleez/4040960 to your computer and use it in GitHub Desktop.
Example of JSON import/export with 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
<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