Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage Getting NULL?

I'm not sure why, as i've done this before and it worked fine, and i'm thinking it might be because of a browser issue/bug:

localStorage.setItem('foo', 'bar')
alert(localStorage.getItem('foo'));

I'm in Firefox 3.6.6 and it alerts "bar" but if I do:

//localStorage.setItem('foo', 'bar')
alert(localStorage.getItem('foo'));

I get NULL. It should return bar still as it's in my storage.

Also, this is just a web page that it's running on.

like image 599
Oscar Godson Avatar asked Aug 31 '26 07:08

Oscar Godson


1 Answers

Are you running the script locally via file:?

If so, Firefox doesn't appear to allow localStorage entries to live beyond unload when file: access is used.

For more info, you may want to look at the question: Is “localStorage” in Firefox only working when the page is online? It's a little dated, but still seems to be applicable.

like image 181
Jonathan Lonowski Avatar answered Sep 01 '26 21:09

Jonathan Lonowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!