Forked from robnyman/Create-open-IndexedDB-database.js
Created
February 23, 2012 20:53
-
-
Save ZachMoreno/1894981 to your computer and use it in GitHub Desktop.
Create/open IndexedDB database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IndexedDB | |
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB, | |
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction, | |
dbVersion = 1; | |
// Create/open database | |
var request = indexedDB.open("elephantFiles", dbVersion); | |
request.onsuccess = function (event) { | |
console.log("Success creating/accessing IndexedDB database"); | |
db = request.result; | |
db.onerror = function (event) { | |
console.log("Error creating/accessing IndexedDB database"); | |
}; | |
// Interim solution for Google Chrome to create an objectStore. Will be deprecated | |
if (db.setVersion) { | |
if (db.version != dbVersion) { | |
var setVersion = db.setVersion(dbVersion); | |
setVersion.onsuccess = function () { | |
createObjectStore(db); | |
getImageFile(); | |
}; | |
} | |
else { | |
getImageFile(); | |
} | |
} | |
else { | |
getImageFile(); | |
} | |
} | |
// For future use. Currently only in latest Firefox versions | |
request.onupgradeneeded = function (event) { | |
createObjectStore(event.target.result); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment