admin管理员组文章数量:1331686
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: /
(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?
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/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?
Share Improve this question asked Mar 29, 2013 at 0:08 Adam RybakAdam Rybak 531 silver badge4 bronze badges 2-
This works okay for me in both cases, but I had to move the
createObjectStore
toonupgradeneeded
– Explosion Pills Commented Mar 29, 2013 at 4:16 - If you have python: "python -m http.server" starts a web server on port 8000 in the local directory. – 79E09796 Commented Aug 8, 2013 at 16:11
3 Answers
Reset to default 3In case anyone is looking for an updated answer to this 6-year-old question, both Chrome and Safari allow local HTML files to access IndexedDB API now, without the need for a local server. IE continues to hold out on this it seems. Unsure about Edge or Firefox.
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.
IndexedDB is disabled when run from file:/// for security. It's unclear if you control the browser parameters. If you do, you can pass --allow-file-access-from-files which will allow IndexedDB to work from the file:/// origin.
本文标签: javascriptIndexedDB over local HTML fileStack Overflow
版权声明:本文标题:javascript - IndexedDB over local HTML file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742250827a2440727.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论