IDBFactory
接口在
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
.
IDBFactory.open
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 待办通知 app ( 实时查看范例 )。
// 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;
};
| 规范 | 状态 | 注释 |
|---|---|---|
|
索引数据库 API 2.0
The definition of 'IDBFactory' in that specification. |
推荐 | |
|
索引数据库 API 草案
The definition of 'IDBFactory' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
IDBFactory
|
Chrome
24
|
Edge 12 |
Firefox
16
|
IE 部分支持 10 | Opera 15 | Safari 7 |
WebView Android
Yes
|
Chrome Android
25
|
Firefox Android 22 | Opera Android 14 | Safari iOS 8 |
Samsung Internet Android
1.5
|
cmp
|
Chrome
24
|
Edge 12 |
Firefox
16
|
IE 部分支持 10 | Opera 15 | Safari 7 |
WebView Android
Yes
|
Chrome Android 25 | Firefox Android 22 | Opera Android 14 | Safari iOS 8 | Samsung Internet Android 1.5 |
databases
|
Chrome 71 | Edge 79 |
Firefox
不支持
No
注意事项
|
IE 不支持 No | Opera 58 | Safari 不支持 No | WebView Android 71 | Chrome Android 71 |
Firefox Android
不支持
No
注意事项
|
Opera Android Yes | Safari iOS 不支持 No | Samsung Internet Android 10.0 |
deleteDatabase
|
Chrome
24
|
Edge 12 |
Firefox
16
|
IE 部分支持 10 | Opera 15 | Safari 7 |
WebView Android
Yes
|
Chrome Android 25 | Firefox Android 22 | Opera Android 14 | Safari iOS 8 | Samsung Internet Android 1.5 |
open
|
Chrome
24
|
Edge 12 |
Firefox
16
|
IE 部分支持 10 | Opera 15 | Safari 7 |
WebView Android
Yes
|
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 |
完整支持
部分支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
要求使用供应商前缀或不同名称。
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
IDBFactory
IDBCursor
IDBCursorSync
IDBCursorWithValue
IDBDatabase
IDBDatabaseException
IDBDatabaseSync
IDBEnvironment
IDBEnvironmentSync
IDBFactorySync
IDBIndex
IDBIndexSync
IDBKeyRange
IDBObjectStore
IDBObjectStoreSync
IDBOpenDBRequest
IDBRequest
IDBTransaction
IDBTransactionSync
IDBVersionChangeEvent
IDBVersionChangeRequest