Exporting WebSQL Data

2019-08-03 06:06发布

One of the major problems with WebSQL is its vulnerability to losing data. Every time the browser history is deleted so is the data stored in your WebSQL tables. Is there any way to export/download the WebSQL data or write it to a file, using only Javascript to prevent data loss? I know you can't access the file system from JavaScript so is this even possible to do? Thanks.

1条回答
倾城 Initia
2楼-- · 2019-08-03 06:33

You could get all the data into a JavaScript variable and then document.location to it.

HTML:

<a href="javascript:onDownload();">Download</a>

JavaScript:

function onDownload() {
    document.location = 'data:Application/octet-stream,' +
                         encodeURIComponent(dataToDownload);
}

(Taken from this blog post: How to Download Data as a File from JavaScript)

查看更多
登录 后发表回答