Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage is not working on google chrome

I am using browsers localStorage to store a value, but while using google chrome, when we refresh the page using window.location.reload(), localStorage.value is flushed. e.g

localStorage.value1=true

after reloading, i am not getting this value1 object in localStorage.

Same code works on mozila firefox, but not in chrome. While using firefox, localstorage value is persistent.

like image 320
Tushar Avatar asked Apr 10 '15 11:04

Tushar


1 Answers

LocalStorage supports only string values, not boolean or others.

Method to store and retrieve values:

Put the value into storage

localStorage.setItem('value1', 'true');

Retrieve the value from storage

var val1 = localStorage.getItem('value1');

Read more on MDN..

like image 113
Shankar Avatar answered Nov 11 '22 09:11

Shankar