WebOS Resets LocalStorage On Browser Close?
I have an HTML5 webapp wherein I use localStorage to retain some client-side user settings between uses. I thought I had it all working well, but I recently find that in the WebOS browser the localStorage items are cleared after the browser is completely closed (all cards--not just my page). It is acting like it is saved to session storage, but that is not the case. Here is a minimal example that illustrates my problem:
<!DOCTYPE html>
<html>
<head>
开发者_JAVA百科 <title>test</title>
<meta charset="utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
$(function() {
$('#btnV').click(function() {
var x = '';
for(var i = 0; i < localStorage.length; i++) {
x += localStorage.key(i) + ':' + localStorage.getItem(localStorage.key(i)) + '<br/>';
}
$('#lbl').empty().append(x);
});
$('#btnS').click(function() {
localStorage.setItem('test', 'blah');
});
});
</script>
</head>
<body>
<span id="lbl"></span>
<input type="button" id="btnS" value="Save" />
<input type="button" id="btnV" value="View" />
</body>
</html>
When I first load the page and click the "View" button, nothing is shown. If I click "Save" and then "View" I will see the item as saved. Refreshing the page and clicking View immediately shows the value is retained across page-reload. However, if I completely close out the browser and then go back in to the page, "View" will show no values as it did the very first time. Am I setting localStorage items incorrectly, or is my WebOS browser configured somehow to do this? I couldn't find anything relevant in the settings.
Thanks...
So far as I know, localStorage is not supported in WebOS 1.4.x. I think I remember seeing it listed as a feature that was enabled in WebOS 2.0 (or maybe 2.1), but I cannot find any documentation on the subject, so I could be misremembering.
Assuming you are storing a small amount of data, user settings are usually more appropriately stored in cookies in WebOS using Mojo.Model.Cookie.
In my own app, I use cookies for user preferences, and store the app data in an HTML5 database database, with my open-source database class making the HTML5 database access less onerous.
精彩评论