Answer the question
In order to leave comments, you need to log in
How to save data from localStorage?
The data in localStorage is saved, but on reboot, it is not loaded
function save() {
var savevalue = document.getElementById("MoneyBalance").innerHTML;
localStorage.setItem('Money', savevalue);
}
function load(){
var storedvalue = localStorage.getItem('Money');
if (storedvalue) {
document.getElementById("MoneyBalance").innerHTML = storedvalue;
}
}
Answer the question
In order to leave comments, you need to log in
the problem is in if (storedvalue)
your storedvalue will not be true and false as you expect, but the value or "undefined". Accordingly, it should be like this:
orif (typeof(storedvalue) !== "undefined")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question