问题描述
我想开发一个使用浏览器与用户交互的应用程序.该应用程序可以脱机使用,并可以通过zip分发.
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.
我想执行的功能将由HTML,CSS,JS处理,并且我想利用IndexedDB功能.
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.
我遇到了IndexedDB(Chrome)的问题,因为相同的代码可以在联机空间中工作,但不能在本地硬盘驱动器位置(file://)工作.
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://).
请参考示例: 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");
};
})();
有什么建议吗?
推荐答案
indexedDB API仅在Web服务器内部起作用.当您使用文件系统导航到它时,它将无法工作. indexedDB API需要使用域上下文,而文件系统不提供该上下文.简而言之,您需要一个URL才能使用api.
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.
这篇关于本地HTML文件上的IndexedDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!