deleteDatabase() 方法在 IDBFactory interface requests the deletion of a database. The method returns an IDBOpenDBRequest object immediately, and performs the deletion operation asynchronously.

If the database is successfully deleted, then a success event is fired on the request object returned from this method, with its result 设为 undefined . If an error occurs while the database is being deleted, then an error event is fired on the request object that is returned from this method.

deleteDatabase() is called, any other open connections to this particular database will get a versionchange 事件。

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

句法

For the current standard:

var request = indexedDB.deleteDatabase(name);
					

For the experimental version with 选项 (see below):

var request = indexedDB.deleteDatabase(name, options);
					

参数

名称
The name of the database you want to delete. Note that attempting to delete a database that doesn't exist does not throw an exception, in contrast to IDBDatabase.deleteObjectStore() , which does throw an exception if the named object store does not exist.
选项 非标
In Gecko, since version 26 , you can include a non-standard optional storage parameter that specifies whether you want to delete a permanent (the default value) IndexedDB, or an indexedDB in temporary storage (aka shared pool.)

返回值

A IDBOpenDBRequest on which subsequent events related to this request are fired.

范例

var DBDeleteRequest = window.indexedDB.deleteDatabase("toDoList");
DBDeleteRequest.onerror = function(event) {
  console.log("Error deleting database.");
};
DBDeleteRequest.onsuccess = function(event) {
  console.log("Database deleted successfully");
  console.log(event.result); // should be undefined
};
					

规范

规范 状态 注释
索引数据库 API 草案
The definition of 'deleteDatabase()' in that specification.
推荐
索引数据库 API 2.0
The definition of 'deleteDatabase()' in that specification.
推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

部分支持

部分支持

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改:
  1. IndexedDB API
  2. IDBFactory
  3. 方法
    1. cmp()
    2. databases
    3. deleteDatabase()
    4. open()
  4. IndexedDB 相关页面
    1. IDBCursor
    2. IDBCursorSync
    3. IDBCursorWithValue
    4. IDBDatabase
    5. IDBDatabaseException
    6. IDBDatabaseSync
    7. IDBEnvironment
    8. IDBEnvironmentSync
    9. IDBFactorySync
    10. IDBIndex
    11. IDBIndexSync
    12. IDBKeyRange
    13. IDBObjectStore
    14. IDBObjectStoreSync
    15. IDBOpenDBRequest
    16. IDBRequest
    17. IDBTransaction
    18. IDBTransactionSync
    19. IDBVersionChangeEvent
    20. IDBVersionChangeRequest

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1