How to make `NativeStorage` defined when invoked from a script executed after a page has been loaded?










0














With the following slight modification of the cordova-plugin-nativestorage's demo example:




index.html's patch



32c32
< <!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> -->
---
> <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
40c40
< <body onload="showData()">
---
> <body>



index.js's patch



78,89c77
< app.initialize();
<
< function showData()
< NativeStorage.getString("dummy_ref_obj",
< function (result)
< alert("After the page has been loaded, the current stored value was: " + result);
< ,
< function (e)
< alert("For the moment, no data saved");
< );
< NativeStorage.clear();
<
---
> app.initialize();


NativeStorage is invoked from a script executed after a page has been loaded (thanks to onload event) but, built and run for:




  • browser platform, it is okay:

    1. at 1st load → "For the moment, no data saved" alert,

    2. save data (say "Foo") → "Saved Data : Foo" alert,

    3. reload the page → "After the page has been loaded, the current stored value was: Foo" alert,



  • android platform, it is not okay:

    1. at 1st load → no alert and the following error:


      Uncaught ReferenceError: NativeStorage is not defined
      at showData (index.js:81) at onload (index.html:40)





My question is: is it possible to make NativeStorage defined when invoked from a script executed after a page has been loaded?



Maybe my problem is because I'm not waiting that the device is ready, before calling I'm calling the NativeStorage plugin but, in such a case, I don't see how to proceed (I'm quite new in Cordova).










share|improve this question























  • Seems to be already answered: stackoverflow.com/a/28995106/1682470.
    – Denis Bitouzé
    Nov 12 at 6:52















0














With the following slight modification of the cordova-plugin-nativestorage's demo example:




index.html's patch



32c32
< <!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> -->
---
> <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
40c40
< <body onload="showData()">
---
> <body>



index.js's patch



78,89c77
< app.initialize();
<
< function showData()
< NativeStorage.getString("dummy_ref_obj",
< function (result)
< alert("After the page has been loaded, the current stored value was: " + result);
< ,
< function (e)
< alert("For the moment, no data saved");
< );
< NativeStorage.clear();
<
---
> app.initialize();


NativeStorage is invoked from a script executed after a page has been loaded (thanks to onload event) but, built and run for:




  • browser platform, it is okay:

    1. at 1st load → "For the moment, no data saved" alert,

    2. save data (say "Foo") → "Saved Data : Foo" alert,

    3. reload the page → "After the page has been loaded, the current stored value was: Foo" alert,



  • android platform, it is not okay:

    1. at 1st load → no alert and the following error:


      Uncaught ReferenceError: NativeStorage is not defined
      at showData (index.js:81) at onload (index.html:40)





My question is: is it possible to make NativeStorage defined when invoked from a script executed after a page has been loaded?



Maybe my problem is because I'm not waiting that the device is ready, before calling I'm calling the NativeStorage plugin but, in such a case, I don't see how to proceed (I'm quite new in Cordova).










share|improve this question























  • Seems to be already answered: stackoverflow.com/a/28995106/1682470.
    – Denis Bitouzé
    Nov 12 at 6:52













0












0








0







With the following slight modification of the cordova-plugin-nativestorage's demo example:




index.html's patch



32c32
< <!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> -->
---
> <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
40c40
< <body onload="showData()">
---
> <body>



index.js's patch



78,89c77
< app.initialize();
<
< function showData()
< NativeStorage.getString("dummy_ref_obj",
< function (result)
< alert("After the page has been loaded, the current stored value was: " + result);
< ,
< function (e)
< alert("For the moment, no data saved");
< );
< NativeStorage.clear();
<
---
> app.initialize();


NativeStorage is invoked from a script executed after a page has been loaded (thanks to onload event) but, built and run for:




  • browser platform, it is okay:

    1. at 1st load → "For the moment, no data saved" alert,

    2. save data (say "Foo") → "Saved Data : Foo" alert,

    3. reload the page → "After the page has been loaded, the current stored value was: Foo" alert,



  • android platform, it is not okay:

    1. at 1st load → no alert and the following error:


      Uncaught ReferenceError: NativeStorage is not defined
      at showData (index.js:81) at onload (index.html:40)





My question is: is it possible to make NativeStorage defined when invoked from a script executed after a page has been loaded?



Maybe my problem is because I'm not waiting that the device is ready, before calling I'm calling the NativeStorage plugin but, in such a case, I don't see how to proceed (I'm quite new in Cordova).










share|improve this question















With the following slight modification of the cordova-plugin-nativestorage's demo example:




index.html's patch



32c32
< <!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> -->
---
> <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
40c40
< <body onload="showData()">
---
> <body>



index.js's patch



78,89c77
< app.initialize();
<
< function showData()
< NativeStorage.getString("dummy_ref_obj",
< function (result)
< alert("After the page has been loaded, the current stored value was: " + result);
< ,
< function (e)
< alert("For the moment, no data saved");
< );
< NativeStorage.clear();
<
---
> app.initialize();


NativeStorage is invoked from a script executed after a page has been loaded (thanks to onload event) but, built and run for:




  • browser platform, it is okay:

    1. at 1st load → "For the moment, no data saved" alert,

    2. save data (say "Foo") → "Saved Data : Foo" alert,

    3. reload the page → "After the page has been loaded, the current stored value was: Foo" alert,



  • android platform, it is not okay:

    1. at 1st load → no alert and the following error:


      Uncaught ReferenceError: NativeStorage is not defined
      at showData (index.js:81) at onload (index.html:40)





My question is: is it possible to make NativeStorage defined when invoked from a script executed after a page has been loaded?



Maybe my problem is because I'm not waiting that the device is ready, before calling I'm calling the NativeStorage plugin but, in such a case, I don't see how to proceed (I'm quite new in Cordova).







cordova-plugins cordova-nativestorage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 6:12

























asked Nov 11 at 21:31









Denis Bitouzé

1598




1598











  • Seems to be already answered: stackoverflow.com/a/28995106/1682470.
    – Denis Bitouzé
    Nov 12 at 6:52
















  • Seems to be already answered: stackoverflow.com/a/28995106/1682470.
    – Denis Bitouzé
    Nov 12 at 6:52















Seems to be already answered: stackoverflow.com/a/28995106/1682470.
– Denis Bitouzé
Nov 12 at 6:52




Seems to be already answered: stackoverflow.com/a/28995106/1682470.
– Denis Bitouzé
Nov 12 at 6:52

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253425%2fhow-to-make-nativestorage-defined-when-invoked-from-a-script-executed-after-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253425%2fhow-to-make-nativestorage-defined-when-invoked-from-a-script-executed-after-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands