IndexedDB over local HTML file

html, indexeddb, javascript

Solution

The indexedDB API only works inside a webserver. When you navigate to it using the file system it won't work. The indexedDB API needs a domain context to work in and the file system doesn't provide that. Short you need an url to use the api.

Problem

I would like to develop an application which uses a browser to interact with the user. The application is to be available offline and distributable via a zip. The functions I would like to perform are to be handled by HTML, CSS, JS and I would like to make use of the IndexedDB functionality. I have hit a problem with IndexedDB (Chrome) in that the same code works in an online space but not from a local hard drive location (file://). Refer to example: http://jsfiddle.net/FwuUD/ ``` (function() { var db; var dbreq = indexedDB.open("TestApp", 2); dbreq.onsuccess = function(e) { alert("Database created"); db = e.target.result; var employeeStore = db.createObjectStore ( "employees", {keyPath: "id"} ); }; dbreq.onerror = function(e) { alert("Database Error: " + e.target.errorCode); }; dbreq.onupgradeneeded = function(e) { alert("Database upgrade needed"); }; })(); ``` Any suggestions?

Original source