Skip to main content

Home/ Groups/ float sticky plan
feng bo

Local Storage - Dive Into HTML5 - 0 views

  • HTML5 Storage support IEFirefoxSafariChromeOperaiPhoneAndroid 8.0+3.5+4.0+4.0+10.5+2.0+2.0+
  • return 'localStorage' in window && window['localStorage'] !== null;
  • The data can be any type supported by JavaScript, including strings, Booleans, integers, or floats. However, the data is actually stored as a string. If you are storing and retrieving anything other than strings, you will need to use functions like parseInt() or parseFloat() to coerce your retrieved data into the expected JavaScript datatype.
  • ...17 more annotations...
  • Calling setItem() with a named key that already exists will silently overwrite the previous value.
  • Calling getItem() with a non-existent key will return null rather than throw an exception.
  • Calling removeItem() with a non-existent key will do nothing.
  • If you call key() with an index that is not between 0–(length-1), the function will return null.
  • attribute unsigned long length
  • If you want to keep track programmatically of when the storage area changes, you can trap the storage event.
  • The storage event is not cancelable. From within the handle_storage callback function, there is no way to stop the change from occurring. It’s simply a way for the browser to tell you, “hey, this just happened. There’s nothing you can do about it now; I just wanted to let you know.”
  • “5 megabytes” is how much storage space each origin gets by default. This is surprisingly consistent across browsers, although it is phrased as no more than a suggestion in the HTML5 Storage specification.
  • “No” is the answer to the next obvious question, “Can I ask the user for more storage space?”
  • The most important part of this function is the caveat that I mentioned earlier in this chapter, which I’ll repeat here: Data is stored as strings. If you are storing something other than a string, you’ll need to coerce it yourself when you retrieve it.
  • gGameInProgress = (localStorage["halma.game.in.progress"] == "true");
  • Web SQL Database support IEFirefoxSafariChromeOperaiPhoneAndroid ··4.0+4.0+10.5+3.0+2.0+
  • openDatabase('documents', '1.0', 'Local document storage', 5*1024*1024, function (db) { db.changeVersion('', '1.0', function (t) { t.executeSql('CREATE TABLE docids (id, name)'); }, error); });
  • I will introduce you to another competing vision for advanced, persistent, local storage for web applications: the Indexed Database API, formerly known as “WebSimpleDB,” now affectionately known as “IndexedDB.”
  • The Indexed Database API exposes what’s called an object store.
  • You don’t construct a statement like "SELECT * from USERS where ACTIVE = 'Y'". Instead, you use methods provided by the object store to open a cursor on the database named “USERS,” enumerate through the records, filter out records for inactive users, and use accessor methods to get the values of each field in the remaining records. An early walk-through of IndexedDB is a good tutorial of how IndexedDB works, giving side-by-side comparisons of IndexedDB and Web SQL Database.
  • Introducing HTML5 Storage
1 - 1 of 1
Showing 20 items per page