javascript - Firefox 中的 "localStorage"是否仅在页面在线时有效?

标签 javascript firefox safari html

所以我在玩弄 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/

相关文章:

javascript - 如何使 HTML Canvas 可点击网格(返回单元格以匹配数组元素?)

javascript - 使用 grunt-sass 编译基础 sass

php - 在firefox中打开PHP文件时提示下载

javascript - Safari 浏览器 Javascript 数组似乎对字符串排序不正确

html - 文本缩进 - 在 Safari 中不显示文本

javascript - 我们应该选择哪个积极维护的 slickgrid 分支?

javascript - 有什么方法可以检查 jQuery 中服务器的可达性测试

javascript - Safari 5.1.4 showModalDialog 返回未定义

javascript - 粗体在 Chrome/Firefox 中太粗了

css - 如何修复响应式设计中的菜单栏