Phonegap - local storage not working - Android

I use Local Storage to pass values ​​between pages to create a scroll for the effect (link to user clicks and scroll to a specific part of the page based on the id)

I used cookies before, but didn’t seem to work on Android, I read that local storage is supported so that it switches to it. It works fine in the browser, but as soon as it is packaged as a native application, do I lose all functionality? The API claims that it should be supported, any ideas?

Here is my code:

Base URL:

var storage = window.localStorage;
$("a.scroll_link").click(function(event) {
    event.preventDefault();
    var value = $(this).attr("id");

        storage.setItem("key",value);

    console.log(value);

    window.location=$(this).attr("href");
});

Receiving URL:

$(function () { 

var value = window.localStorage.getItem("key");

if (value != "" && value != "undefined" && value != null) {
    var storage = window.localStorage;
    storage.setItem("key",value);
    var scroll_type = "";

    if ($.browser.webkit) {
        scroll_type = "body";
    } else {
        scroll_type = "html";
    }

    $(scroll_type)
        .stop()
        .animate({
        //get top-position of target-element and set it as scroll target
        scrollTop: ($("#" + value).offset().top - 25)
        //scrolldelay: 1.5 seconds
    }, {
        duration: 1500,
        complete: function () {
            storage.removeItem("key");
        },
    });
  }
});

The code doesn’t work fine in the browser initially, any ideas?

Thank,

+5
source share
3 answers

document.addEventListener( "deviceready", onDeviceReady, false) $(function() {...}

http://docs.phonegap.com/en/2.5.0/cordova_events_events.md.html#deviceready

+2

1., , . gmh04, , init "deviceready", .

2. window.localStorage.getItem( "" ), null URL? , , . URL- URL-. , localStorage .

+1

, 2.6.0 cordova.js , - localStorage Android:

https://issues.apache.org/jira/browse/CB-3063

In version 2.5.0, it works fine, and it is already fixed on 2.7.0 rc.

+1
source

All Articles