Symbian/Phonegaps-1.10 | TypeError: Result of expression 'localStorage' [null] is not an object

StackOverflow https://stackoverflow.com/questions/12777164

  •  05-07-2021
  •  | 
  •  

Question

I get

TypeError: Result of expression 'localStorage' [null] is not an object

when I try access to localStorage on Symbian/Phonegap app Looks like this related to error that ocurr before:

TypeError: Result of expression 'window.widget.preferenceForKey' [undefined] is not a function. that ocurr in line var pref = window.widget.preferenceForKey(Storage.PREFERENCE_KEY);

function Storage() {
    this.available = true;
    this.serialized = null;
    this.items = null;

    if (!window.widget) {
        this.available = false;
        return;
    }
    var pref = window.widget.preferenceForKey(Storage.PREFERENCE_KEY);

    //storage not yet created
    if (pref == "undefined" || pref == undefined) {
        this.length = 0;
        this.serialized = "({})";
        this.items = {};
        window.widget.setPreferenceForKey(this.serialized, Storage.PREFERENCE_KEY);
    } else {
        this.serialized = pref;'({"store_test": { "key": "store_test", "data": "asdfasdfs" },})';
        this.items = eval(this.serialized);
    }
}

It seems that I need to resolve local storage I don `t know how to do it. Any workaround?

Was it helpful?

Solution

I have actually struggled with this problem myself.

A simple work around is to avoid preferenceForKey all together and instead use preference.

<script>
    var value = "Information to be stored";
    var key = "key";
    widget.preference["key"] = value;
 </script>

You can the retreive this information later.

<script>
    var value = widget.preference["key"];
    alert(value);
</script>

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top