As an added bonus, IE will swat down any attempt to work around this issue.
The sane thing to do would be to stub out your own dummy localStorage so that at least your thing doesn't break when loading it from the local FileSystem:
if (document.all && !window.localStorage)
{
window.localStorage = {};
window.localStorage.removeItem = function () { };
}
Any guesses as to what alert(window.localStorage) will pop up after running that? Did you guess "undefined"???
Thanks, IE! Now there is actually one ugly hack we can do to make this work. Since IE won't let you reuse its reserved word "localStorage", we'll just move the whole thing over to someplace else:
window.localStorageAlias = window.localStorage;
if (document.all && !window.localStorage)
{
window.localStorageAlias = {};
window.localStorageAlias.removeItem = function () { };
}
So now, anywhere you'd normally say localStorage['beans'] = 7, you just do localStorageAlias['beans'] = 7 and you're back in business. Naturally, IE won't actually store anything there between sessions when running from the local filesystem. But at least it won't break.
For extra credit, you can fix the above code to swap in some form of persistent storage that IE will actually use when running locally.