Skip to content
Related Articles

Related Articles

Improve Article

HTML DOM indexedDB deleteDatabase() Method

  • Last Updated : 19 Jul, 2020

The indexedDB deleteDatabase() method is used to request the deletion of a database. The method returns an IDBOpenDBRequest object immediately and performs the deletion operation asynchronously.

Syntax:

var request = indexedDB.deleteDatabase(name);

Parameters: 

  • name: The name of the database you want to delete.

Return value: A IDBOpenDBRequest object after deletion.

Example: In this example, we will open a database and hence, will delete that database using this method.






<!DOCTYPE HTML> 
<html>  
<head>
    <title>indexedDB deleteDatabase() method</title>
</head>   
<body style="text-align:center;">
    <h1 style="color:green;">  
        GeeksforGeeks  
    </h1
    <p
    HTML | indexedDB deleteDatabase() method
    </p>
    <button onclick = "Geeks()">
    Click Here
    </button>     
    <script>
        function Geeks(){
         var request = 
     window.indexedDB.open("newDatabase", 1);
         var DBDeleteReq = 
     window.indexedDB.deleteDatabase("newDatabase");
         DBDeleteReq.onsuccess = function(event) {
              console.log("Database deleted successfully");
}
            console.log(DBDeleteReq);
             console.log(window.indexedDB.databases());
     }
  </script
</body>   
</html>

Output:
Before Button Click:

After Button Click: In the console, the IDBOpenDBRequest object can be seen with a successful delete message.
Also, on checking databases, an Array with 0 databases can be seen.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :