"Cannot call" open "from undefined" when using indexedDB.open

I am new to IndexedDB and I am following this IndexedDB Tutorial tutorial. I'm just trying to create a database and then I can add some records. This is what I still have.

var db = window.indexedDB.open('FriendDB', 'My Friends!'); if (db.version != '1') { // User first visit, initialize database (name, key, auto increment). db.createObjectStore('Friends', 'id', true); db.setVersion('1'); } else { // DB already initialized. } var store = db.openObjectStore('Friends'); var user = store.put({name: 'Eric', gender: 'male', likes: 'html5'}); 

In my console, I get the error message "Can't call the" open "method from undefined", how can I get this to work? Also, if there is a better resource on the Internet that will help me, because I can not find anything on the topic IndexedDB for beginners.

+4
source share
2 answers

Here is the html5rocks indexeddb demo that I improved to work with Mozilla Firefox and added features to view detailed data and edit existing data. Inside there are explanations on how to create db, insert, update and delete data in indexeddb.

https://github.com/denimf/IndexedDbToDo

+2
source

Every time you see code containing a call to setVersion, it uses outdated syntax. Unfortunately, we had to make such a big change so late at the time of writing the spec, but it made using IndexedDB correctly a lot easier, so we decided it was worth it.

There is good documentation on developer.mozilla.org, although this can definitely be improved.

+1
source

All Articles