2016-02-19 115 views
0

我想在我的IE11中使用indexedDB,但它似乎是未定义的。这是代码:如何让indexedDB在IE11中工作?

<!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 

有谁知道什么是错?

感谢

回答

2

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

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

一个简单的例子:

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

例如:

alert(window.indexedDB);