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

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

问题描述

网站用于三星Galaxy Tab与Gingerbread OS。到目前为止使用的浏览器是股票浏览器以及Dolphin HD。当用户进出网络覆盖时,本地存储中的项目似乎随机消失。存储似乎也无法完全避免浏览器崩溃或设备重启。奇怪的部分是存储通常不会完全清除,只是大量的项目丢失。有没有其他人听说过这个问题或有任何建议?

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!)

查看此stackoverflow问题了解更多有关存储事件的详细信息。

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

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

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