Skip to content

Instantly share code, notes, and snippets.

@redknitin
Created September 6, 2015 13:38
Show Gist options
  • Save redknitin/2fcfe4db6626dd9969b4 to your computer and use it in GitHub Desktop.
Save redknitin/2fcfe4db6626dd9969b4 to your computer and use it in GitHub Desktop.
sessionStorage example
<!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