Skip to content

web-storage-API #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions JavaScript/Advance/Web API/web-storage API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>web-storage API</title>
</head>

<body>
<h1>Web Storage API</h1>
<button onclick="DisplayOne()">View Doc</button>
<p id="textOne"></p>
<!-- Example One for localStorage() -->
<h2>localStorage</h2>
<button onclick="DisplayTwo()">view</button>
<p id="textTwo"></p>
<script src="script.js"></script>
<!-- Example Two for sessionStorage() -->
<h2>sessionStorage</h2>
<button onclick="DisplayThree()">view</button>
<p id="textThree"></p>
</body>

</html>
34 changes: 34 additions & 0 deletions JavaScript/Advance/Web API/web-storage API/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Storage API are used for storing data files
There are two main types of storing data in web page
1. localStorage() --> used for storing data permenantly
2. sessionStorage() --> used for storing data for short period of time
*/
let textOne = document.getElementById('textOne');

function DisplayOne() {
textOne.innerHTML = `
<h2>Storage API are of Two Types</h2>
<h3>1. localStorage: ()</h3>
<p>Used for Storing Data Permanently</p>
<h3>2. sessionStorage()</h3>
<p>Used for Storing Data Short Time</p>
`
}

// Example One localStorage()

let textTwo = document.getElementById('textTwo');

function DisplayTwo() {
localStorage.setItem("name", "Azhar");
textTwo.innerHTML = localStorage.getItem("name");
}

// Example Two sessionStorage()

let textThree = document.getElementById('textThree');

function DisplayThree() {
sessionStorage.setItem("name", "Musharraf");
textThree.innerHTML = sessionStorage.getItem("name");
}