IE10中的本地文件可以使用IndexedDB吗? [英] Can local files in IE10 use IndexedDB?

查看:212
本文介绍了IE10中的本地文件可以使用IndexedDB吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个可以在没有互联网的情况下在本地运行的Web应用程序,并将信息存储在本地文件系统中,并在浏览器中运行.我的代码在Chrome和Firefox中有效,但在IE10中,我收到错误消息window.indexedDB未定义

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

来自代码:

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

当其应为[object IDBFactory]时,它将发出未定义"警报.

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

是否有解决办法,或者IE10永远不会允许本地文件使用indexedDB?

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

推荐答案

IndexedDB实例绑定到本地文件不支持的域.至少这是IndexedDB规范所暗示的,但没有这样明确地说明.

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.

某些浏览器(Chrome/Firefox)确实为本地文件实现了该功能,但这可能与处理本地文件的域"的方式有关,这可能与IE不同.

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.

解决这个问题的方法是使用node.js和express.js来提供文件(这也意味着您可以避免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

然后将以下文件用作我的JS(另存为app.js):

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);

最后运行它:

node app.js

这将在以下目录中创建一个Web服务器,将当前目录中的所有文件作为静态文件提供,因此您可以轻松创建HTML文件,而无需创建路由或任何内容.

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.

这篇关于IE10中的本地文件可以使用IndexedDB吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆