是“localStorage"吗?在 Firefox 中只在页面在线时工作? [英] Is "localStorage" in Firefox only working when the page is online?

查看:14
本文介绍了是“localStorage"吗?在 Firefox 中只在页面在线时工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在玩弄 HTML 5 和 localStorage,我注意到我的值只有在本地主机上的 Firefox 中运行页面时才会被存储(即 http://127.0.0.1:8000/test/index.html),但是当我在本地运行文件时 (file:///C:/test/index.html) 我的值没有被存储.Safari 4 对这两种设置都没有问题.那么有人知道这是否是设计使然 -> Mozilla 开发人员中心的 DOM 存储

So I'm toying around with HTML 5 and the localStorage and I'm noticing that my values only get stored when I run the page in Firefox on the local host (i.e. http://127.0.0.1:8000/test/index.html), but when I run the file locally (file:///C:/test/index.html) my values don't get stored. Safari 4 has no problems with both setups. So does anybody know if this is by design -> DOM Storage on the Mozilla Developer Center

(Firefox 2 允许访问存储域层次结构中较高的对象比当前文档.这不是Firefox 3 中不再允许安全原因.此外,这建议添加到 HTML 5 中从 HTML 5 规范中删除支持 localStorage,这是在 Firefox 3.5 中实现.)

(Firefox 2 permitted access to storage objects higher in the domain hierarchy than the current document. This is no longer allowed in Firefox 3, for security reasons. In addition, this proposed addition to HTML 5 has been removed from the HTML 5 specification in favor of localStorage, which is implemented in Firefox 3.5.)

或者是否有解决方法?
我想知道因为只能在线工作的离线存储听起来很傻:P

Or if there is a workaround?
I wonder because offline storage that works only online sounds silly :P

如果有人想知道,代码就这么简单:

If anybody wonders, the code is as easy as it gets:

function save()
{
 localStorage.setItem('foo','bar');
}

function load()
{
 var test = localStorage.getItem('foo');
 alert(test);
}

推荐答案

这似乎是一个错误:错误 507361 - localStorage 在 file:///文档中不起作用
希望快点好起来!

It seems a bug: Bug 507361 - localStorage doesn't work in file:/// documents
Hope is fixed soon!

2011-09-13:修复了错误,在Mozilla8"中实现.我用 Firefox 8 对此进行了测试,现在可以使用了.

2011-09-13: Bug fixed, implemented in 'Mozilla8'. I tested this with Firefox 8 and it works now.

这篇关于是“localStorage"吗?在 Firefox 中只在页面在线时工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆