网站HTML删除数据库中数据语句,如何以编程方式删除WebSQL中的数据库?

开发人员选项

无法以编程方式枚举或删除数据库(还)。

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") });

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值