Anne van Kesteren

Web Storage Elsewhere

While testing Internet Explorer 8 I also took a shot at Firefox 3.6something and Safari 4 beta. From these three browsers only Firefox returns null for keys not part of the storage object as per the Web Storage specification. The others return undefined which makes more sense ECMAScript-wise. I’m wondering why the Safari and IE team did not feed this information back. That could have prevented this.

Also, how do I get a storage event to dispatch in Firefox and Safari? Reading the specification it should be as simple as this:

window.onstorage = function(e) { alert(e) }
localStorage.x = "x"

That does not work however. It also does not work in Internet Explorer until you realize it dispatches the event to a different object! (I’m still not quite over this one.) Anyone an idea?


  1. It seems I was wrong about nonexistent keys. localStorage.missing has to return undefined (bug in Firefox), but localStorage.getItem("missing") has to return null. So Safari and Internet Explorer are correct on this front after all. Ugly though.

    Posted by Anne van Kesteren at

  2. Events are dispatched in Gecko if you use addEventListener as it turns out. Have not checked WebKit yet.

    Posted by Anne van Kesteren at