Search code examples
javascripthtmlcordovaphonegap

Validity of data stored in a HTML element in a Cordova app


Say the cordova app has a div element "text" built-in.

<div id="text"></div>

Now during app execution, if value was written to the div using js

document.getElementById('text').innerHTML = "123456";

How long will the data survive? Until app close? Until device boot?

And how safe is the data stored? Can any other app access this data?


Solution

  • On deploying your code from cordova to android device, following observations are made -

    1. Data Longevity - The data will survive only till the app is exited (by clearing from background apps or running apps). If we switch to it from recent apps the data will be same.
    2. OnReboot - Once you reboot the device the data '123456' is lost. You have to run the script again to restore the data.
    3. Security - Other apps can't access the data from java script unless you allow any external scripts run in the app. (ex- while using iframes for external contents).

    Read more about Security in Cordova Security Guide .