HTML5本地存储:存储和下载文件
如何使用HTML5本地存储保存一个小的exe文件,然后单击按钮下载它?HTML5本地存储不适用于文件 请在此处查看Mozilla的文档: 而是针对键/值对HTML5本地存储:存储和下载文件,html,local-storage,Html,Local Storage,如何使用HTML5本地存储保存一个小的exe文件,然后单击按钮下载它?HTML5本地存储不适用于文件 请在此处查看Mozilla的文档: 而是针对键/值对 // Save data to the current local store localStorage.setItem("username", "John"); // Access some stored data alert( "username = " + localStorage.getItem("username")); 要开始
// Save data to the current local store
localStorage.setItem("username", "John");
// Access some stored data
alert( "username = " + localStorage.getItem("username"));
要开始下载,您可能需要看一个像
Localstorage
这样的问题,因为您认为它不是数据库,甚至不是文件系统,它只是一些简单的JSON
文件,以键:值
对存储少量数据
如果您以前使用过JSON,那么很容易理解它背后的思想
下面是从本地存储设置和检索值的示例:
locastorage.setItem('KEY',JSON.stringify('VALUE'));
// KEY is kind of like the variable name and the VALUE is the actual Data
JSON.parse(locastorage.getItem('KEY'));
// You use the KEY to access the value
// Using JSON methods stringify and parse just to be on the safer side.
但是这个链接呢:它说你实际上可以将任何文件保存为blob。你为什么要这样做?需要明确的是,用户无法访问这些文件——它们由浏览器存储在数据库文件中。