Skip to content

Commit 7f33a43

Browse files
authored
Merge pull request #646 from Santwana786/main
Create Session Storage object using HTML
2 parents 246c7ac + 51257b0 commit 7f33a43

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Session Storage object using HTML

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
function clickCounter() {
6+
if (typeof(Storage) !== "undefined") {
7+
if (sessionStorage.clickcount) {
8+
sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
9+
} else {
10+
sessionStorage.clickcount = 1;
11+
}
12+
document.getElementById("result").innerHTML = "You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
13+
} else {
14+
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
15+
}
16+
}
17+
</script>
18+
</head>
19+
<body>
20+
21+
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
22+
<div id="result"></div>
23+
<p>Click the button to see the counter increase.</p>

0 commit comments

Comments
 (0)