Web Storage
Web Storage allows you to store key-value pairs in the user's browser, using the localStorage or sessionStorage objects in JavaScript. localStorage stores data permanently, even when the browser is closed, while sessionStorage stores data only for the duration of the session.
<input type="text" id="name">
<button onclick="saveName()">Save Name</button>
<script>
function saveName() {
const name = document.getElementById("name").value;
localStorage.setItem("name", name);
}
const savedName = localStorage.getItem("name");
if (savedName) {
alert(`Welcome back, ${savedName}!`);
}
</script>
No comments:
Post a Comment