localStorage Getting NULL?

China☆狼群 提交于 2020-01-04 04:07:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3303978/localstorage-getting-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!