Working with Cookies
The cookie is a well-known browser feature, created early on to store state or session information. Mojo cookies have a similar purpose, and are technically related to browser cookies, but with an object interface to simplify use by webOS applications. Mojo cookies typically store small amounts of data that will preserve application state and related information, such as preference settings.
Palm webOS creates a fake domain for running applications, based on each application ID. Cookies created by the application code are associated with that domain, so unlike browser cookies, they’ll never be present as part of web requests to other services; they are strictly for local storage.
You should limit cookies to less than 4kB, but can have multiple cookies within an application if needed. You can remove cookies if they are no longer needed and the framework will delete an application’s cookies if the application is removed from the device.
Mojo.Model.Cookie(id)
opens the
cookie that matches the ID argument or, if there is no match, creates a
new cookie with that ID. There are three methods:
get()
Retrieves the object stored in the cookie (if it exists) or returns
undefined
.put()
Updates the value of the named cookie with an optional date/time after which the object is deleted.
remove()
Removes the named cookie and deletes the associated data.
The Cookie function and all of its methods are synchronous, unlike Depot and the database functions, making for a simpler calling interface ...
Get Palm webOS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.