Saturday, March 6, 2010

LocalStorage

HTML 5 provides several options to persist data on the client. One of these options is LocalStorage, a simple way to save key value pairs. The API are
  • getItem(key)
  • setItem(key, value)
  • removeItem(key)
  • clearAll()
It couldn't be easier, it's like the browser provides a hash table and handles persisting it. Unfortunately, the keys and values are strings. It's very similar to cookies except the information is not passed with the HTTP request.

localStorage and sessionStorage are supported by Firefox 3.5, Safari 4.0, and IE8. localStorage databases are scoped to an HTML5 origin, basically the tuple (scheme, host, port). This means that the database is shared across all pages on the same domain, even concurrently by multiple browser tabs. However, a page connecting over http:// cannot see a database that was created during an https:// session.

Storage events are fired and can be listened to so additional windows and or tabs can update based on data changes.

Notes: Got error QUOTA_EXCEEDED_ERR 22 when running in Safari with Private Browsing on. Error codes.

No comments:

Post a Comment