O'Reilly logo

HTML5: Your visual blueprint™ for designing rich web pages and applications by Adam McDaniel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

STORE AN OBJECT USING THE INDEXEDDB API

You can store an object into an IndexedDB object store using the add() request method generated by a read-write transaction. Because all transactions run asynchronously, the request/event model allows your code to know when a transaction has completed.

Only an array or generic object can be stored, and not simple strings or numbers. Custom objects that are built with constructors will be destroyed, but their properties and values will survive.

 function addObject(object) { var transaction = db.transaction(objectStore, IDBTransaction. READ_WRITE); var store = transaction. objectStore(objectStore); var request = store.add(object); request.onsuccess = function(event) {...}; request.onerror = function(event) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required