Javascript Browser Storage setItem() Method by session storage

Introduction

Using session storage instead of local storage.

Set the value of the specified session storage item:

sessionStorage.setItem("test1", "Lorem ipsum");

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

View in separate window

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

<script>

function createItem() {/*w  w  w.j  a va2 s .  c o m*/
  sessionStorage.setItem("test1", "Lorem ipsum");
}

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

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



PreviousNext

Related