所以我在玩弄 HTML 5 和 localStorage,我注意到只有当我在本地主机上的 Firefox 中运行页面时(即 http://127.0.0.1:8000/test/index.html )我的值才会被存储,但是当我运行文件时在本地 (file:///C:/test/index.html) 我的值没有被存储。 Safari 4 对这两种设置都没有问题。 那么有人知道这是否是设计使然 -> DOM Storage on the Mozilla Developer Center
(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
如果有人想知道,代码非常简单:
function save()
{
localStorage.setItem('foo','bar');
}
function load()
{
var test = localStorage.getItem('foo');
alert(test);
}
最佳答案
这似乎是一个错误:Bug 507361 - localStorage doesn't work in file:/// documents
希望尽快修好!
2011-09-13:错误修复,在“Mozilla8”中实现。我用 Firefox 8 对此进行了测试,现在可以使用了。
关于javascript - Firefox 中的 "localStorage"是否仅在页面在线时有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1492942/