如何让indexedDB在IE11中工作?

ome*_*ega 0 html5 indexeddb internet-explorer-11

我想在我的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> 
Run Code Online (Sandbox Code Playgroud)

它提醒:

Your browser doesn't support a stable version of IndexedDB.
11
CSS1Compat
Run Code Online (Sandbox Code Playgroud)

有谁知道什么是错的?

谢谢

Jos*_*ell 5

我怀疑你是试图从本地文件(例如c:\test.html)而不是HTTP资源这样做.IE可能限制从文件(或非HTTP)来源访问API.

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

一个更简单的例子:

<script>
alert(window.indexedDB);
</script>
Run Code Online (Sandbox Code Playgroud)
  • 本地档案: undefined
  • 历任: [object IDBFactory]

例如: