HTML5 Local Storage Not Persistent

社会主义新天地 提交于 2019-11-30 01:48:23

问题


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?

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.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/8072797/html5-local-storage-not-persistent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!