HTML Window sessionStorage गुण हमें वेब ब्राउज़र में केवल एक सत्र के लिए कुंजी/मान युग्म डेटा संग्रहीत करने की अनुमति देता है, जिसका अर्थ है कि ब्राउज़र टैब बंद होने पर डेटा हटा दिया जाता है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
window.sessionStorage
आइए HTML विंडो सेशनस्टोरेज प्रॉपर्टी का एक उदाहरण देखें -
उदाहरण
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%) no-repeat;
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 30%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
.show{
font-size:1.2rem;
}
</style>
<body>
<h1>HTML Window sessionStorage Property Demo</h1>
<button onclick="store()" class="btn">Store 'John Smith' Name to sessionStorage</button>
<button onclick="display()" class="btn">Display sessionStorage stored value</button>
<div class="show"></div>
<script>
function store(){
sessionStorage.setItem('firstName','John');
sessionStorage.setItem('lastName','Smith');
document.querySelector('.show').innerHTML='Name store successfully';
}
function display(){
var firstName=sessionStorage.getItem('firstName');
var lastName=sessionStorage.getItem('lastName');
document.querySelector('.show').innerHTML='Name stored in sessionStorage is: '+ firstName +' '+lastName;
}
</script>
</body>
</html> आउटपुट

"स्टोर 'जॉन स्मिथ' पर क्लिक करें ' नाम से सेशनस्टोरेज” बटन को सेशनस्टोरेज में नाम स्टोर करने के लिए:

अब “प्रदर्शन सत्रसंग्रहित मान . पर क्लिक करें "संग्रहीत मान प्रदर्शित करने के लिए बटन -

अब आप यह समझने के लिए कि यह कैसे काम करता है, अपने डेव टूल्स में सेशन स्टोरेज भी खोल सकते हैं -
