javascript - localForage 在 Chrome 中找到数据,在 Firefox 中找不到

标签 javascript google-chrome firefox localforage

我在 Firefox 中使用 localForage 时遇到一些奇怪的行为。我设置了一个页面来使用标准“setItem”表单加载两个数组:

 <script src="localforage.js"></script>
 <body>
<script>
var data = [1,2,3,4,5];
localforage.setItem("saveData", data, function(err, value) {
if (err) {
 console.error('error: ', err);
} else {    
console.log("Data Saved");
}});

localforage.getItem("saveData", function (err, value) {
if (err) {
   console.error('error: ', err);
} else {
    console.log('saveData is: ', value);
    localforage.keys(function(err, keys) {
    console.log("Keys: " + keys);
    console.log("Number of keys: " + keys.length);
    });
}});
</script>
</body>
</html>

数组已正确保存。

然后我使用完全相同的“getItem”函数创建了第二个页面。

在Chrome中,数据显示出来,但在Firefox中根本没有列出,并且无法打开。

还有其他人经历过这种情况吗?在 Firefox 中,即使在同一 session 中打开第二个页面也无法找到已保存的文件。我尝试过更改 security.fileuri.strict_origin_policy,但没有什么区别。

我宁愿使用 Firefox,但如果它不断丢失保存的数据,我就不能使用。

最佳答案

我也遇到了同样的问题,但经过一番研究、尝试和讨论后解决了。 FireStorage Plus 等扩展!简单的 session 存储不能完美地检测此数据,特别是在原始根页面/文件以外的页面/文件上执行时。

我的解决方案是使用 native FF 存储检查器。只有这样我才能看到我丢失的所有数据。即使正在设置,这些扩展程序也不会显示数据。

引用:localForage setItem/getItem unreliable in Firefox / FireStorage Plus

enter image description here

此外,如需进一步解决 localForage 问题,请尝试使用 IRC 聊天#localforage:https://webchat.freenode.net/并寻找tofumatt。他是你想与之交谈的大师。 ^5

关于javascript - localForage 在 Chrome 中找到数据,在 Firefox 中找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33973634/

相关文章:

javascript - Chrome 扩展 - 更改弹出窗口

javascript - 调试网页(Firebug、IE F12工具)

firefox - 用于测试移动设计的浏览器插件

javascript:在可重用的 d3js 图表中广泛使用 'this'

javascript - React : Warning: setState(. ..):在现有状态转换期间无法更新

javascript - 这个正则表达式在做什么?

google-chrome - 从 Native Client/Pepper Plugin 调用 Windows API

jQuery ajax 在 HTTP 206 上使 chrome 崩溃(部分内容)

android - 水平图像库 - 空白 : nowrap messing up max-height: 100% on Firefox for Android

javascript - 在 PHP 代码中显示/隐藏表格