IDBDatabase:close() 方法
注意:此功能在 Web Workers 中可用。
IDBDatabase 介面的 close() 方法會立即返回,並在一個單獨的執行緒中關閉連線。
在所有使用此連線建立的事務完成之前,連線實際上並未關閉。呼叫此方法後,不能再為該連線建立新事務。如果存在待處理的關閉操作,則建立事務的方法會丟擲異常。
語法
js
close()
引數
無。
返回值
無(undefined)。
示例
js
// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4); // opening a database.
// Create event handlers for both success and failure of
DBOpenRequest.onerror = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Error loading database.";
};
DBOpenRequest.onsuccess = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Database initialized.";
// store the result of opening the database in the db variable.
db = DBOpenRequest.result;
// now let's close the database again!
db.close();
};
規範
| 規範 |
|---|
| Indexed Database API 3.0 # ref-for-dom-idbdatabase-close② |
瀏覽器相容性
載入中…
另見
- 使用 IndexedDB
- 開始事務:
IDBDatabase - 使用事務:
IDBTransaction - 設定鍵的範圍:
IDBKeyRange - 檢索和修改資料:
IDBObjectStore - 使用遊標:
IDBCursor - 參考示例:待辦事項通知(檢視即時示例)。