1

Possible Duplicate:
localStorage object is undefined in IE

The following code gives me SCRIPT5009: 'Storage' is undefined in IE9. It works in Chrome, Safari, Firefox.

Storage.prototype.setObject = function(key, value) {
    this.setItem(key, JSON.stringify(value));
}

udpate I'm serving the page from Apache server, not accessing it from local file system so the following don't apply:

localStorage object is undefined in IE

local storage in IE9 fails when the website is accessed directly from the file system

update 2 found problem, see my answer.

Community
  • 1
  • 1
dev.e.loper
  • 35,446
  • 76
  • 161
  • 247

2 Answers2

1

Found the problem. I must specify DOCTYPE <!DOCTYPE html> Even though other browsers don't care IE does.

Thanks to @Rocket Hazmat for pointing it out.

Without DOCTYPE, IE goes into Quirks mode. With DOCTYPE, IE is goes into Standards mode. My guess is that IE needs to be in Standards mode in order to access HTML5 features.

dev.e.loper
  • 35,446
  • 76
  • 161
  • 247
0

Guessing here...

IE 9 does not seem to support localStorage when run on a local filesystem: local storage in IE9 fails when the website is accessed directly from the file system

More detail can be found here: http://www.wintellect.com/CS/blogs/jprosise/archive/2011/03/10/using-html5-web-storage-for-interprocess-communication.aspx

So you can either run it on an external server - or check if it is supported in your script:

if ("localStorage" in window && window["localStorage"] != null) {

    // Local storage supported

}
Community
  • 1
  • 1
madflow
  • 7,718
  • 3
  • 39
  • 54
  • I'm serving the page from Apache server, not accessing it from local file system. Also, I belive IE9 supports storage http://caniuse.com/#feat=namevalue-storage – dev.e.loper Dec 28 '12 at 20:44
  • Yes it does! But it seems not on a local filesystem. That was my guess ;) – madflow Dec 28 '12 at 20:54