IDBFactory

IDBFactory interface of the IndexedDB API lets applications asynchronously access the indexed databases. The object that implements the interface is window.indexedDB . You open — that is, create and access — and delete a database with this object, and not directly with IDBFactory .

注意: 此特征可用于 Web 工作者 .

方法

IDBFactory.open
The current method to request opening a connection to a database .
IDBFactory.deleteDatabase
A method to request the deletion of a database.
IDBFactory.cmp
A method that compares two keys and returns a result indicating which one is greater in value.
IDBFactory.databases
A method that returns a list of all available databases, including their names and versions.

范例

In the following code snippet, we make a request to open a database, and include handlers for the success and error cases. For a full working example, see our To-do Notifications app ( view example live .)

// In the following line, you should include the prefixes of implementations you want to test.
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
// DON'T use "var indexedDB = ..." if you're not in a function.
// Moreover, you may need references to some window.IDB* objects:
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
// (Mozilla has never prefixed these objects, so we don't need window.mozIDB*)
// Let us open version 4 of our database
var DBOpenRequest = window.indexedDB.open("toDoList", 4);
// these two event handlers act on the database being opened successfully, or not
DBOpenRequest.onerror = function(event) {
  console.error("Error loading database.");
};
DBOpenRequest.onsuccess = function(event) {
  console.info("Database initialised.");
  // store the result of opening the database in the db variable. This is used a lot later on, for opening transactions and suchlike.
  db = DBOpenRequest.result;
};
					

规范

规范 状态 Comment
Indexed Database API 2.0
The definition of 'IDBFactory' in that specification.
Recommendation
Indexed Database API Draft
The definition of 'IDBFactory' in that specification.
Recommendation

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
IDBFactory Chrome 24
24
23 — 57
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 16
16
10 — 16
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 部分支持 10 Opera 15 Safari 7 WebView Android Yes
Yes
? — 57
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 25
25
25 — 57
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 22 Opera Android 14 Safari iOS 8 Samsung Internet Android 1.5
1.5
1.5 — 7.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
cmp Chrome 24
24
23 — 24
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 16
16
10 — 16
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 部分支持 10 Opera 15 Safari 7 WebView Android Yes
Yes
? — ?
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 25 Firefox Android 22 Opera Android 14 Safari iOS 8 Samsung Internet Android 1.5
databases
Chrome 71 Edge 79 Firefox 不支持 No
注意事项
No
注意事项
bug 934640 .
IE 不支持 No Opera 58 Safari 不支持 No WebView Android 71 Chrome Android 71 Firefox Android 不支持 No
注意事项
No
注意事项
bug 934640 .
Opera Android Yes Safari iOS 不支持 No Samsung Internet Android 10.0
deleteDatabase Chrome 24
24
23 — 24
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 16
16
10 — 16
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 部分支持 10 Opera 15 Safari 7 WebView Android Yes
Yes
? — ?
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 25 Firefox Android 22 Opera Android 14 Safari iOS 8 Samsung Internet Android 1.5
open Chrome 24
24
23 — 24
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 16
16
10 — 16
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 部分支持 10 Opera 15 Safari 7 WebView Android Yes
Yes
? — ?
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 25 Firefox Android 22 Opera Android 14 Safari iOS 8 Samsung Internet Android 1.5
Available in workers Chrome Yes Edge ≤18 Firefox 37 IE ? Opera Yes Safari ? WebView Android Yes Chrome Android Yes Firefox Android 37 Opera Android Yes Safari iOS ? Samsung Internet Android Yes

图例

完整支持
完整支持
部分支持
部分支持
不支持
不支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
见实现注意事项。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅