Appframe Knowledge Base


1 hits
0

Using af.common.localStorage to save UI state

/* If localStorage is not supported by your browser,
   the settings will be kept in memory and reset on reload.
   If you need to check if your settings will be persisted,
   you can use this command to test for support: */

af.common.localStorage.isPersisted();
// > true

/* When getting a setting and the value does not exist
    you can specify a default value as the second parameter
    and that value will be returned if no data is in the localStorage */

af.common.localStorage.get("mySetting", "myDefaultValue");
// > "myDefaultValue"

/* Values that are stored in localStorage gets stored per article
    by reading the af.article.id value, so make sure this is correct */

af.common.localStorage.set("mySetting", "someOtherValue");
// > undefined

/* You can also remove individual keys */

af.common.localStorage.remove("mySetting");
// > true

/* Or you can clear everything beeing stored for the active article */

af.common.localStorage.clear();
// > undefined

common web · Perma link post comment Posted by: Jan Henrik H. Meling (14-mai-2012)