IDBFactory.deleteDatabase()

by 2 contributors:

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 null. 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.

Syntax

For the current standard:

var request = window.indexedDB.deleteDatabase("toDoList");

For the experimental version with options (see below):

var request = window.indexedDB.deleteDatabase("toDoList", storage: "temporary");

Returns

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(request.result); // should be null
};

Parameters

name
The name of the database.
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 in temporary storage (aka shared pool.)

Specifications

Specification Status Comment
Indexed Database API
The definition of 'deleteDatabase' in that specification.
Candidate Recommendation  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 23webkit
24
10 moz
16.0 (16.0)
10, partial 15 7.1
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support 4.4 22.0 (22.0) 1.0.1 10 22 Not supported

Be careful in Chrome as it still implements the old specification along with the new one. Similarly it still has the prefixed webkitIndexedDB property even if the unprefixed indexedDB is present.

See also

Document Tags and Contributors

Contributors to this page: chrisdavidmills, fscholz
Last updated by: chrisdavidmills,