--- title: IDBEnvironment slug: Web/API/IDBEnvironment translation_of: Web/API/IDBEnvironment ---
{{APIRef()}}
注意! : 对于 Firefox 52, the property defined in this mixin has been moved to the {{domxref("WindowOrWorkerGlobalScope")}} mixin, and other browsers will follow suit. Look to that page for up-to-date details. IndexedDB API
IndexedDB API提供的帮助类IDBEnvironment包含了一个indexedDB 属性, 这个属性可以比较方便的操作IndexedDB. 它是由{{domxref("window")}} 和{{domxref("Worker")}} 实现的最顶级 IndexedDB接口.
{{AvailableInWorkers}}
下述代码演示了如何创建一个异步打开数据库的请求, 当该请求的onsuccess 回调被执行时, 该数据库被打开.
var db;
function openDB() {
var DBOpenRequest = window.indexedDB.open("toDoList");
DBOpenRequest.onsuccess = function(e) {
db = DBOpenRequest.result;
};
}
| 规范 | 状态 | 说明 |
|---|---|---|
| {{SpecName('IndexedDB', '#idl-def-IDBEnvironment', 'IDBEnvironment')}} | {{Spec2('IndexedDB')}} |
{{Compat("api.IDBEnvironment")}}