HTML and CSS Reference
In-Depth Information
As I mentioned in the API overview section, if the key doesn't
exist in the storage object, then it will return null. This isn't a
problem for the native JSON parsers as JSON.parse(null) returns
null—as you would expect. However, for Douglas Crockford's
JavaScript version, passing null will throw an error. So if you know
it's possible that Crockford's JSON JavaScript library is being
loaded, protect against this error by using the following:
var videoDetails = JSON.parse(sessionStorage.getItem
¬ ('videoDetails') || 'null');
This ensures that if null is returned from the getItem method,
you pass in a JSON-encoded version of null, and thus the
JavaScript based JSON parser won't break.
Using debugging tools
Although there's good support for the Web Storage API, the
debuggers are still maturing. So aside from inspecting the
sessionStorage or the localStorage there are just a few
tools available. Often from the debugging tools, you can
modify keys and values and delete entries.
NoTE To e n a b l e t h e
Developer menu in Safari,
go to Preferences and from the
Advanced tab, check the Show
Developer Menu in the Menu
Bar box. Chrome's debugger is
available from the “spanner,”
To o l s m e n u , a n d D e v e l o p e r To o l s .
While I refer to WebKit, in this section I'm covering Safari,
the nightly build of Safari (WebKit) and Google Chrome. Web-
Kit's developer tools allows us to view the localStorage and
sessionStorage values stored as shown in Figure 6.1 .
FIguRE 6.1 Chrome's storage
debugger (Safari has very
nearly the same interface).
Search WWH ::

Custom Search