<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
Ello
</body>
</html>
JavaScript
///http://www.html5rocks.com/en/tutorials/indexeddb/todo/
//instantiation
var html5rocks = {};
html5rocks.indexedDB = {};
html5rocks.indexedDB.db = null;
/*
//example 1
//Define an open method
html5rocks.indexedDB.open = function () {
var request = indexedDB.open("todos","This is a description of the database.");
request.onsuccess = function (e) {
html5rocks.indexedDB.db = e.target.result;
//more stuff later
};
request.onfailure = html5rocks.indexedDB.onerror;
};
*/
//example 2
//Define an open method
html5rocks.indexedDB.open = function() {
var request = indexedDB.open("todos", "This is a description of the database");
//if request is successful preform the callback
request.onsuccess = function(e) {
var v = "1.0";
html5rocks.indexedDB.db = e.target.result;
var db = html5rocks.indexedDB.db;
// We can only create Object stores in a setVersion transaction;
if (v != db.version) {
var setVrequest = db.setVersion(v);
}
// onsuccess is the only place we can create Object Stores
setVrequest.onfailure = html5rocks.indexedDB.onerror;
setVrequest.onsuccess = function(e) {
//creates the object store
var store = db.createObjectStore("todo", {
keyPath: "timeStamp"
});
//Calls the object store
html5rocks.indexedDB.getAllTodoItems();
};
};
request.onfailure = html5rocks.indexedDB.onerror;
};
//Addin an entry
html5rocks.indexedDB.addTodo = function(todoText) {
//get ref to the db
var db = html5rocks.indexedDB.db;
//init a read_write transaction
var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE, 0);
//get ref to object store
var store = trans.objectStore("todo");
//puts new object into object store
var request = store.put({
"text": todoText,
"timeStamp": = new Date().getTime()
});
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.