문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top