简体   繁体   English

HTML5本地存储不持久

[英]HTML5 Local Storage Not Persistent

Site is used on Samsung Galaxy Tab with the Gingerbread OS. 网站用于三星Galaxy Tab与Gingerbread OS。 Browsers used so far are the stock browser as well as Dolphin HD. 到目前为止使用的浏览器是Stock浏览器以及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? 有人听说过这个问题还是有什么建议吗?

Edit: By local storage I mean, 编辑:通过本地存储我的意思是,

localStorage["Key"] = value;

Retrived using: 使用以下方法重复:

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. 我发现的一切都说本地存储应该存在,所以我真的不知道从哪里开始。

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... 我在PhoneGap中使用localStorage / sessionStorage,从未让它们消失......

Add the following event handler: 添加以下事件处理程序:

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

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!) 您还可以在adb logcat中记录更详细的信息(例如正在访问的密钥!)

Have a look at this stackoverflow question for more details on Storage events. 有关存储事件的更多详细信息,请查看此stackoverflow问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM