localStorage Demo



Saved name is:





html Code


<!DOCTYPE html>
<html>
<body>

<h1>localStorage Demo</h1>

<button onclick="store()">Store "John Smith" to localStorage</button>
<br><br>
<button onclick="retrieve()">Return name from localStorage</button>

<p>Saved name is:</p>
<p id="demo"></p>

<script>
// Set Item
function store() {
localStorage.setItem("name", "John Smith");
alert("John Smith saved to localStorage");
}
// Retrieve
function retrieve() {
document.getElementById("demo").innerHTML = localStorage.getItem("name");
}
</script>

</body>
</html>