cordova-jquerymobile-boilerplate
cordova-jquerymobile-boilerplate copied to clipboard
Unable to get localStorage working
I have 2 Android devices (4.2+ and 2.3) and I couldn't get either the window.localStorage API or the simple localStorage API to work between app restarts on either device. Has anyone else experienced this issue?
Here's the little code I have. #contact is a page (I just have one index.html with multiple <div data-role="page" ...> tags.
This worked in the web browser using the window.localStorage API.
var startApp = function() {
$('#contact').live( 'pageshow',function(event){
var contactInfo = localStorage.getItem("contactInformation");
if (contactInfo) {
$.each(contactInfo.split('&'), function (index, elem) {
var vals = elem.split('=');
$("[name='" + vals[0] + "']").val(vals[1]);
});
}
$('#contact-form').on('submit', function () {
var serialized = $(this).serialize();
localStorage.setItem("contactInformation", serialized);
console.log("Contact info saved.");
return true;
});
});
};