HTML and CSS Reference
In-Depth Information
In addition, comment out the tasks-webstorage.js from the tasks.html page and add in tasks-
indexeddb.js in its place. We will eventually move to a model where the browser will
choose the best implementation, but for now we will concentrate on getting the IndexedDB
implementation working.
<!--script src="scripts/tasks-webstorage.js"></script-->
<script src="scripts/tasks-indexeddb.js"></script>
To begin with we are going to implement the init method. As with the Web storage im-
plementation, this will check that IndexedDB is supported by the browser, but unlike Web
Storage, there is a specific operation that needs to be performed: opening the database.
The following is the implementation:
storageEngine = function() {
var database;
var objectStores;
return {
init : function(successCallback, errorCallback) {
if (window.indexedDB) {
var request ='DB', 1)
request.onsuccess = function(event) {
database = request.result;
request.onerror = function(event) {
errorCallback('storage_not_initalized', 'It is not possible to initialized storage');
} else {
errorCallback('storage_api_not_supported', 'The web storage api is not supported');
initObjectStore : function(type, successCallback, errorCallback) {
Search WWH ::

Custom Search