Can local files in IE10 use IndexedDB?

强颜欢笑 提交于 2019-12-13 02:16:16

问题


I'm trying to write a web app that can be run locally without internet and stores info on the local filesystem and is run in the browser. My code works in Chrome and Firefox but in IE10 I get the error that window.indexedDB is undefined

from the code:

window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
alert( window.indexedDB );

This alerts "undefined" when it should be [object IDBFactory].

Is there a way around this or will IE10 never allow local files to use indexedDB?


回答1:


IndexedDB instances are tied to the domain which a local file doesn't support. At least this is what is implied by the IndexedDB spec but it's not explicitly spelled out like that.

Some browser (Chrome/Firefox) do implement it for local files but that could be to do with how that handle a "domain" for local files, which is probably different to IE.

The way I get around this is to use node.js and express.js to just serve out the files (and it also means you can avoid the IE security policy warnings), so all I do is:

npm install express

Then use the following file as my JS (saved as app.js):

var express = require('express');
var app = express();

app.use(express.static(__dirname));

app.listen(3000);

And finally run it:

node app.js

This will create a webserver in the following directory serving out all the files from the current directory as static files, so you can easily hit your HTML file without creating routes or anything.




回答2:


If you open the IE dev console for an HTML document loaded from the filesystem, you can try to load indexedDB from the console.

When I try, I get the error

DOM7005: Indexed DB is only available on websites with http or https URL schemes.

Bummer. If Node.js isn't an option, there's also IIS Express. 7.5 works all the way back to Windows XP and can even be configured to run out of an XCOPY deployment.

Portable IIS Express instructions




回答3:


I've got the joy of IE11 spewing hundreds of those warnings and I'm not even using Indexed DB in any form, its just the Microsoft IE11 debugger shitting the bed for some reason.

"DOM7005: Indexed DB is only available on websites with http or https URL schemes."

starts scrolling down the console when I break and start to want to look at the local variables to see whats what.

What I'm loading, is a local file system SVG graphic that has embedded javascript (ecmascript) to examine, manipulate and return information based on the SVG documents DOM.



来源:https://stackoverflow.com/questions/16287134/can-local-files-in-ie10-use-indexeddb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!