如何让 indexedDB 在 IE11 中工作?

How to get indexedDB to work in IE11?

我想在我的 IE11 中使用 indexedDB,但它似乎未定义。这是代码:

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>



    <script>
        window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;

        window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
        window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange

        if (IDBTransaction) {
            window.IDBTransaction.READ_WRITE = window.IDBTransaction.READ_WRITE || 'readwrite';
            window.IDBTransaction.READ_ONLY = window.IDBTransaction.READ_ONLY || 'readonly';
        }
        if (!window.indexedDB) {
            window.alert("Your browser doesn't support a stable version of IndexedDB.")
        }
        alert(document.documentMode);
        alert(document.compatMode);
    </script>
</head>

<body>
 The content of the document......
</body>

</html> 

它提醒:

Your browser doesn't support a stable version of IndexedDB.
11
CSS1Compat

有人知道怎么回事吗?

谢谢

我怀疑您正试图从本地文件(例如 c:\test.html)而不是 HTTP 资源执行此操作。 IE 可能限制从文件(或非 HTTP)来源访问 API。

如果我将您的内容保存在本地文件中,它会像您在 IE 中指出的那样发出警报。如果我通过服务器提供内容,它会正常工作。

一个更简单的例子:

<script>
alert(window.indexedDB);
</script>
  • 本地文件:undefined
  • 服务:[object IDBFactory]

例如:

alert(window.indexedDB);