3

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.

Oscar Godson
  • 31,662
  • 41
  • 121
  • 201
  • Sorry, updated my question, but basically, it outputs null, but it should still return bar, as it's in my storage no matter if I leave the page, close the browser, or erase my cache/history/etc. – Oscar Godson Jul 21 '10 at 22:09
  • Where are you running this code from? A filesystem web page, a local server web page, a remote server web page, or from a Firefox add-on? – Chetan Jul 21 '10 at 22:11
  • 2
    @Oscar: Where are you running the web page from? If it's from filesystem (`file://`), Firefox might permanently not store anything in localStorage. – Chetan Jul 21 '10 at 22:19
  • Thats probably it. Damn it, why would they do that? I guess i dont see the security issue here. – Oscar Godson Jul 21 '10 at 22:30
  • @Oscar – I think the issue is that different applications running from the local filesystem have access to the same variables, as there are no domains to distinguish between them. – Marcel Korpel Jul 23 '10 at 23:38

1 Answers1

7

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.

Community
  • 1
  • 1
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
  • Yeah, i think thats it... i was running it locally ill try uploading it, but reading this seems like thats what it is – Oscar Godson Jul 21 '10 at 22:23