2016-02-19 114 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);