Why does window.indexedDB evaluate to undefined? (How to use IndexedDB?)
I am messing around with HTML5's IndexedDB.
Below is a simple code from http://html5-demos.appspot.com/static/html5storage/index.html#slide31 that is not working for me in Chrome or Firefox, it is giving me this message in Firebug:
Uncaught TypeError: Cannot call method 'open' of undefined`
for the 1st line of the code, which is:
var db = window.indexedDB.open('FriendDB', 'My Friends!'); // exception here
Can someone help me to get this working please?
I know this works on the browser because this interactive slide works: http://html5-demos.appspot.com/static/html5storage/index.html#slide34
You have to use the prefixed version for each browser (window.webkitIndexedDB or window.mozIndexedDB). Then you can do something like:
window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
and then use window.indexedDB everywhere in your code.