HTML and CSS Reference
In-Depth Information
Dropping a database in IndexedDB is easy and involves just one method: the de-
leteDatabase method of the IndexedDB object. Call deleteDatabase while
passing the name of the target object store, and then the entire database will be removed.
Step 8: Drop the database to clear all tasks
To enable a user to clear all tasks from the application, you need to do two things:
1 . Create a new function, dropDatabase , that will remove the tasks database, and
therefore all task items, from the application.
2 . Call dropDatabase from the resetSettings function you created earlier
in the localStorage section of this chapter. Adding this call now completes re-
setSettings 's function, which is to reset a user's personal settings and erase all of
a user's tasks.
For browsers that don't support IndexedDB, you'll need to provide a Web SQL fallback as
well. In this case, you won't drop the database; you'll just delete the tasks table from the
Web SQL database.
To define the dropDatabase function, add the code from the next listing directly below
the code from the previous listing in your app.js file.
Listing 5.16. app.jsā€”Dropping the database
With the dropDatabase function defined, you can now call it from the resetSet-
tings function you created in section 5.2.3 . In this function, locate the line loca-
tion.hash = '#list'; and add the following line just beneath it:
Search WWH ::

Custom Search