是否有任何方法可以使Chrome扩展使用一个或多个文本文件作为数据库?
我环顾四周,我发现的唯一相似的东西是这个- http://eligrey.com/demos/FileSaver.js/
顺便说一句。我正在使用jQuery(从web抓取信息并将其存储在个人电脑上的文件)
对于Chrome扩展,您可以使用chome.storage
API。
免责声明:正如我在我的评论和chrome扩展文档警告说:
机密用户信息不应存储!存储区域未加密。
From the docs:
您需要在清单中启用存储权限:
{
"name": "My extension",
...
"permissions": [
"storage"
],
...
}
然后你可以使用:
function saveChanges() {
// Get a value saved in a form.
var theValue = textarea.value;
// Check that there's some code there.
if (!theValue) {
message('Error: No value specified');
return;
}
// Save it using the Chrome extension storage API.
chrome.storage.sync.set({'value': theValue}, function() {
// Notify that we saved.
message('Settings saved');
});
}
chrome.storage
仅适用于chrome扩展(这是很好的这个问题)。
但是,还有其他选择(你必须检查每个浏览器的兼容性):
Web存储,索引数据库,Web SQL查看这个链接了解更多关于它们的优缺点:http://csimms.botonomy.com/2011/05/html5-storage-wars-localstorage-vs-indexeddb-vs-web-sql.html