The deleteDatabase()
method of the 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
set to 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.
When deleteDatabase()
is called, any other open connections to this particular database will get a versionchange event.
Syntax
For the current standard:
var request = indexedDB.deleteDatabase(name);
For the experimental version with options
(see below):
var request = indexedDB.deleteDatabase(name, options);
Parameters
- name
- 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. - options Non-standard
- 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 intemporary
storage (aka shared pool.)
Return value
A IDBOpenDBRequest
on which subsequent events related to this request are fired.
Example
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 };
Specifications
Specification | Status | Comment |
---|---|---|
Indexed Database API The definition of 'deleteDatabase()' in that specification. |
Recommendation | |
Indexed Database API 2.0 The definition of 'deleteDatabase()' in that specification. |
Editor's Draft |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 23webkit 24 (unprefixed) |
(Yes) | 10 moz 16.0 (16.0) |
10, partial | 15 | 7.1 |
Available in workers | (Yes) | (Yes) | 37.0 (37.0) | ? | (Yes) | ? |
Indexed Database 2.0 | 58 | ? | ? | ? | 45 | ? |
Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | 22.0 (22.0) | 1.0.1 | 10 | 22 | 8 |
Available in workers | (Yes) | (Yes) | (Yes) | 37.0 (37.0) | (Yes) | ? | (Yes) | ? |
Indexed Database 2.0 | 58 | 58 | ? | ? | ? | ? | 45 | ? |
See also
- Using IndexedDB
- Starting transactions:
IDBDatabase
- Using transactions:
IDBTransaction
- Setting a range of keys:
IDBKeyRange
- Retrieving and making changes to your data:
IDBObjectStore
- Using cursors:
IDBCursor
- Reference example: To-do Notifications (view example live.)