Javascript Browser Storage getItem() Method by session storage

Introduction

Using session storage instead of local storage.

Get the value of the specified session storage item:

var x = sessionStorage.getItem("test1");

This example demonstrates how to use the getItem() method to get the value of a specified session storage item.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="createItem()">Create session storage item</button>
<button onclick="myFunction()">Get the item value</button>
<p id="demo"></p>

<script>

function createItem() {/* www.  j  a  va 2s .c o  m*/
  sessionStorage.test1 = "hello";
}

function myFunction() {
  var x = sessionStorage.getItem("test1");
  document.getElementById("demo").innerHTML = x;
}

</script>
</body>
</html>



PreviousNext

Related