beannshie beannshie - 3 years ago 131
HTML Question

LocalStorage won't save properly

I have a problem where the value of the localStorage item won't get saved.

I have no idea why, it's fine untill I refresh.

The variable / local storage item is "logged".

Here is my code :

HTML and JavaScript

Thank you.

Answer Source

In my opinion, at the beginning of the javascript code, you have to store and retrieve local storage for 'logged' by checking if it exists or not:

 if(localStorage.getItem("logged") !== undefined) {
    logged = localStorage.getItem("logged");
else {
    localStorage.setItem("logged", logged);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download