为什么 Internet Explorer 11 检测不到 indexedDB

Why does Internet Explorer 11 not detect indexedDB

我正在尝试使用 indexedDB 实现一个简单的网络应用程序,并使用这段代码来检测浏览器兼容性:

if(!window.indexedDB) {
   alert("Your browser does not support indexedDB.");
}

当运行在Chrome时它没有打开警告框(如预期的那样),但是当运行在IE中时,警告框弹出。我认为这只是一个糟糕的 Internet Explorer 版本,所以我检查了一下。当时是11,我去http://caniuse.com看支持什么版本,支持IE 11。出了什么问题?我是否使用了错误的代码来检测 indexedDB?

IE11 确实支持 IndexedDB,而且您提供的代码看起来也很合理,因此如果未出现警报,则一定有其他因素。您没有过多提及您的环境,因此需要注意以下几点:

  • 如果这是一个通过 HTTP or HTTPS, it's likely you're not loading the page in edge mode, as in you may be using a DOCTYPE that does not render in edge mode (formerly known as standards mode). If you're not sure what this means, please make sure the first line in your webpage is <!doctype HTML>. (The tip about using F12 tools to verify the document is a good one 加载的 public 网页。)

  • 如果此网页 运行 在您的本地网络(包括本地硬盘驱动器)上,则可能正在加载该页面 in compatibility view。您想要在 "content="ie=edge".

  • 中添加 x-ua-compatible header
  • 另一种可能性是,由于本地组策略设置 and/or 其他环境因素,IndexedDB 可能被禁用。这很难预测,但一种响应方式可能是尝试在完全不同的环境中使用 claims to work 的代码来测试该功能,例如连接到其他环境的 PC,例如你的家庭网络。

目前不确定具体建议是什么,但(希望)这里有一些有用的东西。

希望这对您有所帮助...

-- 兰斯