HTML5 本地存储不持久 [英] HTML5 Local Storage Not Persistent

查看:26
本文介绍了HTML5 本地存储不持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该网站在具有 Gingerbread 操作系统的 Samsung Galaxy Tab 上使用.目前使用的浏览器是股票浏览器以及海豚高清.当用户进出网络覆盖范围时,本地存储中的项目似乎随机消失.存储似乎也无法完全承受浏览器崩溃或设备重启.奇怪的部分是存储通常不会完全清除,只是大量物品丢失.有没有其他人听说过这个问题或有什么建议?

Site is used on Samsung Galaxy Tab with the Gingerbread OS. Browsers used so far are the stock browser as well as Dolphin HD. Items in local storage seem to at random disappear when users go in and out of network coverage. Storage also seems to not be able to fully survive browser crashes or device restarts. Weird part is storage doesn't usually clear out completely, just a large number of items go missing. Anyone else heard of this problem or have any suggestions?

我的意思是本地存储

localStorage["Key"] = value;

检索使用:

localStorage.getItem("Key");

在任何情况下,在添加到本地存储后,站点都可以直接检索和使用数据.但是,通常在漫游或浏览器/平板电脑崩溃之后的某个时间,数据不再存在.我发现的所有内容都表明本地存储应该保持不变,所以我真的不知道从哪里开始.

In every case, directly after adding to local storage, the site is able to retrieve and use the data. However, sometime after this usually after roaming or browser/tablet crashes, the data is no longer there. Everything I've found says local storage should persist, so I don't really know where to go from here.

推荐答案

再调试一下怎么样?也许您自己的代码以某种方式覆盖了它?我在 PhoneGap 中使用 localStorage/sessionStorage 并且从未让它们消失......

How about debugging this a bit further? Maybe your own code is somehow overwriting it? I am using localStorage/sessionStorage in PhoneGap and never had them disappearing...

添加以下事件处理程序:

Add the following event handler:

window.addEventListener("storage", function(e) {
   console.debug(e);
}, false);

每次访问存储时都会触发(并登录到控制台,在桌面浏览器上).您还可以在 adb logcat 中记录更详细的信息(例如正在访问的密钥!)

Which will fire (and log to console, on desktop browser) every time the storage is accessed. You could also log more detailed info to be seen in your adb logcat (like the key being accessed!)

看看 this stackoverflow question 了解有关存储事件的更多详细信息.

Have a look at this stackoverflow question for more details on Storage events.

这篇关于HTML5 本地存储不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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