Created
September 6, 2015 13:38
-
-
Save redknitin/2fcfe4db6626dd9969b4 to your computer and use it in GitHub Desktop.
sessionStorage example
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
<!doctype html><html> | |
<head> | |
<script> | |
function putInStorage() { | |
itemz = [1, 2, 3]; | |
sessionStorage.setItem("itemz", JSON.stringify(itemz)); | |
} | |
function getFromStorage() { | |
itemz = JSON.parse(sessionStorage.getItem("itemz")); | |
for (i=0; i<itemz.length; i++) { | |
alert(itemz[i]); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="alert(window.sessionStorage.length);">Session Size</button> | |
<button onclick="putInStorage();">Set</button> | |
<button onclick="getFromStorage();">Get</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment