Saving State with User Preferences
In many instances, you may need to persistently store small amounts of personalization information for a user. One of the features available within the OpenSocial gadgets JavaScript libraries provides a facility to help you do just that.
To integrate this feature, you need to take a few steps:
Within the
ModulePrefsnode of the gadget spec file, add aRequireelement includingsetprefsto enable theflashJavaScript library.Include:
<Require feature="setprefs"/>
Add a
UserPrefnode with the value matching the user preference element you wish to persistently store.When you wish to set a new user preference, you will need to call the
set()method of thegadgets.Prefsobject.Method call:
set(...);
There are several methods available that provide user preference getting and setting abilities, listed in Table 4-3.
Table 4-3. User preference methods
Method | Description |
|---|---|
| Allows you to set the persistent state of a user preference variable. Parameters include:
|
| Obtains a
|
| Obtains a |
| Obtains a |
<Module> <ModulePrefs> <Require feature="setprefs" /> </ModulePrefs> <UserPref ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access