开发人员选项
无法以编程方式枚举或删除数据库(还)。
Chrome开发者可以导航到chrome://settings/cookiessearch并删除任何数据库Opera开发者可以导航到opera://settings/cookies
真正删除数据库的唯一方法(和其他所有内容)
一个新的规格说这可能是在这个function与响应头和JavaScript。 缺点是你不能控制什么被删除,所以你需要首先创build一个备份,除非你想清除所有的东西
2.1.3。 存储参数
存储参数指示服务器希望移除与特定响应的URL的来源相关联的本地存储的数据。 这包括存储机制,如( localStorage,sessionStorage,[INDEXEDDB],[WEBDATABASE]等 ),以及切线相关的机制,如服务工作者注册。
JS:
navigator.storage.clear({ types: [ "storage" ], includeSubdomains: true // false by default });
响应标题:
res.header("Clear-Site-Data", "storage; includeSubdomains");
但是这对于任何浏览器都是不可行的
最好的解决scheme为客户(而不是开发者)
/* This will fetch all tables from sqlite_master * except some few we can't delete. * It will then drop (delete) all tables. * as a final touch, it is going to change the database * version to "", which is the same thing you would get if * you would check if it the database were just created * * @param name [string] - the database to delete * @param cb [function] - the callback when it's done */ function dropDatabase(name, cb){ // empty string means: I do not care what version, desc, size the db is var db = openDatabase(name, "", "", ""); function error(tx, err){ console.log(err); } db.transaction(ts => { // query all tabels from sqlite_master that we have created and can modify var query = "SELECT * FROM sqlite_master WHERE name NOT LIKE 'sqlite\\_%' escape '\\' AND name NOT LIKE '\\_%' escape '\\'"; var args = []; var success = (tx, result) => { var rows, i, n, name; rows = result.rows; n = i = rows.length; // invokes cb once it's called n times function after(){ if (--n < 0) { // Change the database version back to empty string // (same as when we compear new database creations) db.changeVersion(db.version, "", function(){}, error, cb); } } while(i--){ // drop all tabels and calls after() each time name = JSON.stringify(rows.item(i).name); tx.executeSql('DROP TABLE ' + name, [], after, error); } // call it just 1 more extra time incase we didn't get any tabels after(); }; ts.executeSql(query, args, success, error); }); }
用法
dropDatabase("database", function(){ console.log("done") });