Home > Software engineering >  How to prevent data from disappearing on webpage
How to prevent data from disappearing on webpage

Time:09-09

I want to prevent my data from disappearing on the webpage whenever I refresh the page. Please how do I go about that with local storage in JavaScript?

CodePudding user response:

I would like to suggest resources like https://www.w3schools.com/

but take a look at this

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

<script>
// Set Item
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("demo").innerHTML = localStorage.getItem("lastname");
</script>

CodePudding user response:

Hey Oluwatosin Sunday For a very roboust project you will have to learn database but let's say if you want the user to login after he has logged in the first time on your website then you will use localStorage how to use it?

// to add new item to the cache memory of the user
localStorage.setItem('key', //anything here);
//to get it
localStorage.getItem('key');
// to remove it
localStorage.removeItem('key');
// to remove all of it
localStorage.clear();


  • Related