Web Storage 是html5的本地存储规范

  支持:移动平台基本支持 (opera mini除外) ie8+ff chrome 等 支持

它包含2个:
  sessionStorage 会话存储     停留期: 会话期间 关闭网页之前
  localStorage 本地存储          停留期:删除之前 改变之前 都存在本地。

因为sessionStorage 与localStorage  都继承于 Web Strogage。 他们的一些属性跟方法都一致。

//判断浏览器支持情况
if(window.sessionStorage){ }
if(window.localStorage){ }

以localStorage 为例:

/**
* 属性: length
* 方法: getItem(key)
* setItem(key,value)
* removeItem(key) 删除某一个
* clear() 清除所有的
* key(index) 获取本地存储的第index个的value
*/
//注意存储的是字符窜。json格式 通过JSON.stringify 来转化成字符串。
// 同样 取出来的值也是字符串 通过 JSON.parse 来转化成 json数据;        var data={
name:"aa",
age:"25",
job:'f2e',
test:'test'
} ;
localStorage.clear();
localStorage.setItem('User',JSON.stringify(data)); // var user_data = JSON.parse(localStorage.getItem('User')); //console.log(user_data); //Object {name: "aa", age: "25", job: "f2e"}

浏览器有个 stroage事件 可以监听。

window.addEventListener('storage',function(e){

    console.log(e)

},false);

不过比较不同的是 storage 事件不是监听本页面,而是监听本域上其它页面对localStorage的更改。

示例:http://yueyao.github.io/project/test/pages/local2.html 

         http://yueyao.github.io/project/test/pages/local1.html

尝试点击1 或者2 页面 看看另外一个页面的响应

HTML5API___Web Storage的更多相关文章

  1. Azure Queue Storage 基本用法 -- Azure Storage 之 Queue

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure File Storage 基 ...

  2. Azure File Storage 基本用法 -- Azure Storage 之 File

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Blob Storage 基 ...

  3. HTML5_06之拖放API、Worker线程、Storage存储

    1.拖放API中源对象与目标对象事件间的数据传递: ①创建全局变量--污染全局对象:  var 全局变量=null;  src.ondragstart=function(){   全局变量=数据值;  ...

  4. HTML5权威指南--Web Storage,本地数据库,本地缓存API,Web Sockets API,Geolocation API(简要学习笔记二)

    1.Web Storage HTML5除了Canvas元素之外,还有一个非常重要的功能那就是客户端本地保存数据的Web Storage功能. 以前都是用cookies保存用户名等简单信息.   但是c ...

  5. MySQL报错:Got error 28 from storage engine

    今天碰到数据库出错: Got error 28 from storage engine 查了一下,数据库文件所在的盘应该没事,应该是数据库用的临时目录空间不够 问题原因: 磁盘临时空间不够导致. 解决 ...

  6. Html 5 Web Storage

    HTML5 中使用Web Storage 技术进行本地存储,能够在Web 客户端进行数据存储.WebStorage 曾今属于HTML5的规范,目前已经被独立出来形成单独的规范体系.简单来说使用Web本 ...

  7. Azure Blob Storage 基本用法 -- Azure Storage 之 Blob

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Table storage ...

  8. Azure Table storage 基本用法 -- Azure Storage 之 Table

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table,其中的 Table 就是本文的主角 Azure Tabl ...

  9. Windows Azure Storage (6) Windows Azure Storage之Table

    <Windows Azure Platform 系列文章目录> 最近想了想,还是有必要把Windows Azure Table Storage 给说清楚. 1.概念 Windows Azu ...

随机推荐

  1. spring常量值注入

    <context:property-placeholder location="classpath:resources/*.properties" /> @Value( ...

  2. html5test

    html5test Github https://github.com/NielsLeenheer/html5test 主程序是 scripts/7/engine.js 目前看到的分类大部分是基于判断 ...

  3. CentOS 7 下yum安装xtrabackup备份工具

    第一步:安装xtrabackup的数据库 yum install https://www.percona.com/redir/downloads/percona-release/redhat/late ...

  4. CentOS和Redhat发行版linux内核版本的对应关系

    由于Redhat和CentOS的发行版本现在众多,所以我们应该知道CentOS和Redhat及linux内核之间版本的对应关系对维护系统还是很有帮助的.对应的列表如下: Redhat 9.0————— ...

  5. ORACLE-Kill 杀死正在执行的Oracle存储过程和死锁语句

    ORACLE-Kill 杀死正在执行的Oracle存储过程和死锁语句 存储过程 1.找到正在执行的存储过程的 sid ,serial# select   b.sid,b.SERIAL#,a.OBJEC ...

  6. SD和SDHC和SDXC卡的区别是什么

    SD卡,SDHC卡,SDXC卡区别在规格不一样,SD卡最大支持2GB容量,SDHC 最大支持32GB容量,SDXC 最大支持2TB(2048GB)容量,支持SDXC卡的数码设备是兼容支持SD卡与SDH ...

  7. win7系统还原教程

    当我们的win7系统出现故障了导致系统不能稳定运行而我们没有更好的解决办法时,我们一般的方式是对系统进行还原或重新安装win7系统了,本文主要讨论win7系统还原,抛开第三方软件不说,win7系统自带 ...

  8. IE添加信任站点并设置允许ActiveX控件的VBS脚本

    Set objFSO = CreateObject("Scripting.FileSystemObject") Set WSHShell = CreateObject(" ...

  9. Windows Azure Marketplace 为新增的 50 个国家/地区提供,并推出了令人振奋的新增内容,包括我们自己的 Bing 光学字符识别服务

    尊敬的 Windows Azure Marketplace 用户: 我们有一些让人激动的新闻与您分享:我们现在为新增的 50 个国家/地区提供 Marketplace.自此,我们提供支持的国家/地区总 ...

  10. 2016 Multi-University Training Contest 1 总结

    算是组队后第一次打比赛吧. 09题开始就有人过了,看到题目,这不是轮廓线DP的裸题么?!!,一发WA告终,然后发现题目是有改动的.还是太心急了. 然后我读了第一题,是最小生成树求期望距离,我把题意说了 ...