IDBFactory.deleteDatabase()

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.

Note: This feature is available in Web Workers.

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.
optionsNon-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 in temporary 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 Draft
The definition of 'deleteDatabase()' in that specification.
Recommendation
Indexed Database API 2.0
The definition of 'deleteDatabase()' in that specification.
Recommendation Initial definition.

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
deleteDatabaseChrome Full support 24
Full support 24
No support 23 — 24
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 12Firefox Full support 16
Full support 16
No support 10 — 16
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Partial support 10Opera Full support 15Safari Full support 7WebView Android Full support Yes
Full support Yes
No support ? — ?
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android Full support 25Firefox Android Full support 22Opera Android Full support 14Safari iOS Full support 8Samsung Internet Android Full support 1.5

Legend

Full support
Full support
Partial support
Partial support
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

See also