简体   繁体   中英

localStorage doesn't save the data

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM