1

I'm developing firefox extension and going to save local data in localStorage. So I testing my extension on local saved web page.

window.content.localStorage.setItem('name', 'Hello World!');

And window.content.localStorage.getItem('name') return correct string. But when I reopened this testing page window.content.localStorage.getItem('name') returns 'null'. Why? It's because I'm using local page?

Castro
  • 87
  • 1
  • 2
  • 9

1 Answers1

4

Different browsers currently treat file: urls differently for localStorage.

This means that if you are just creating a file on your computer and opening it directly, you will have different results depending on the browser you are using.

I believe this was changed in Firefox 8, so if you use 8 or higher it should work for you. Other browsers I am not sure about.

Edit: Is "localStorage" in Firefox only working when the page is online? seems to confirm that FF3-8 will not work how you are doing it.

Community
  • 1
  • 1
Alan Geleynse
  • 24,821
  • 5
  • 46
  • 55
  • IE9 and older Firefoxes for sure did not allowed you to use localStorage on localhost or file urls, chrome treated all file urls as same domain (as of summer 2011, maybe it changed), and opera treated same folder as same domain. Firefox was going to adopt Opera's model, afaik, in FF8. But i have not tested. https://bugzilla.mozilla.org/show_bug.cgi?id=507361 – c69 Jan 04 '12 at 23:15