Storage 的使用
//是否不支持storage
isNoStorage: function(){
if(typeof(Storage)=="function" || window.sessionStorage){
return false;
}else {
return true;
}
},
// 保存
setStorage: function(key, value, isLocal){
var text = JSON.stringify({value: value});
if(isLocal)
window.localStorage.setItem(key, text); //localStorage 方法存储的数据没有时间限制。第二天、第二周或下一年之后,数据依然可用。
else
window.sessionStorage.setItem(key, text); // sessionStorage闭浏览器窗口后,数据会被删除。
},
// 提取
getStorage: function(key, isLocal){
var text;
if (isLocal)
text = window.localStorage.getItem(key);
else
text = window.sessionStorage.getItem(key);
if (!text) return null;
var obj = JSON.parse(text);
if (obj)
return obj.value;
},
// 移除
removeStorage: function(key, isLocal){
if (isLocal)
window.localStorage.removeItem(key);
else
window.sessionStorage.removeItem( key );
},
// 清除所有
clearStorage: function(){
window.localStorage.clear();
},
// 清理过期Storage (value值为日期 )
clearExpireStorage: function(curTime, key, isLocal){
var Storage = isLocal ? window.localStorage : window.sessionStorage;
var expireTime = 7*24*3600*1000;
for(var i=0, leng=Storage.length; i<leng; i++){
var skey = Storage.key(i);
var value = Storage.getItem(key);
if(key==skey.substring(0,key.length) && ((Number(curTime)-Number(value))>expireTime)){
Storage.removeItem(skey)
}
}
}
Storage 的使用的更多相关文章
- Azure Queue Storage 基本用法 -- Azure Storage 之 Queue
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure File Storage 基 ...
- Azure File Storage 基本用法 -- Azure Storage 之 File
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Blob Storage 基 ...
- HTML5_06之拖放API、Worker线程、Storage存储
1.拖放API中源对象与目标对象事件间的数据传递: ①创建全局变量--污染全局对象: var 全局变量=null; src.ondragstart=function(){ 全局变量=数据值; ...
- HTML5权威指南--Web Storage,本地数据库,本地缓存API,Web Sockets API,Geolocation API(简要学习笔记二)
1.Web Storage HTML5除了Canvas元素之外,还有一个非常重要的功能那就是客户端本地保存数据的Web Storage功能. 以前都是用cookies保存用户名等简单信息. 但是c ...
- MySQL报错:Got error 28 from storage engine
今天碰到数据库出错: Got error 28 from storage engine 查了一下,数据库文件所在的盘应该没事,应该是数据库用的临时目录空间不够 问题原因: 磁盘临时空间不够导致. 解决 ...
- Html 5 Web Storage
HTML5 中使用Web Storage 技术进行本地存储,能够在Web 客户端进行数据存储.WebStorage 曾今属于HTML5的规范,目前已经被独立出来形成单独的规范体系.简单来说使用Web本 ...
- Azure Blob Storage 基本用法 -- Azure Storage 之 Blob
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Table storage ...
- Azure Table storage 基本用法 -- Azure Storage 之 Table
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table,其中的 Table 就是本文的主角 Azure Tabl ...
- Windows Azure Storage (6) Windows Azure Storage之Table
<Windows Azure Platform 系列文章目录> 最近想了想,还是有必要把Windows Azure Table Storage 给说清楚. 1.概念 Windows Azu ...
- [New Portal]Windows Azure Storage (14) 使用Azure Blob的PutBlock方法,实现文件的分块、离线上传
<Windows Azure Platform 系列文章目录> 相关内容 Windows Azure Platform (二十二) Windows Azure Storage Servic ...
随机推荐
- localhost, 127.0.0.1, 0.0.0.0
总结: localhost:是一个域名.域名可以认为是某个ip的别称,便于记忆.通常localhost对应的ip是127.0.0.1,不过这个也可以设置,参见知乎回答 127.0.0.1:是一个回环地 ...
- 【SpringBoot+Mybatis+thymeleaf报错】Error resolving template "XXX", template might not exist or might not be accessible by any of the configured
解决方法一: 原因:在使用springboot的过程中,如果使用thymeleaf作为模板文件,则要求HTML格式必须为严格的html5格式,必须有结束标签,否则会报错. 在application.y ...
- Python抓取远程文件获取真实文件名
用urllib下载远程文件并转存到hdfs服务器,在下载时,下载地址中不一定包含文件名,需要从连接信息中获取. 1 file_url = request.form.get('file_url') 2 ...
- LINQ中的"延迟查询"特性【转】
本文转载自:LINQ中的"延迟查询"特性 详细了解“延迟查询”:C#学习笔记(八)—–LINQ查询之延迟执行 很多标准查询操作符的设计原型都是返回一个IEnumerable< ...
- HDU – 1050 Moving Tables
http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...
- 【App性能分析】:tracelog分析法
tracelog可以记录每个OpenGL函数调用的消耗时间,所以很多时候用来作performance分析.目前只支持安卓4.1以上的版本设备 1,目前Android Device Monitor最新的 ...
- 查看APK包签名的方法。
1.查看 keystore $ keytool -list -keystore debug.keystore 结果: Keystore type: JKS Keystore provider: SUN ...
- Mac 10.12安装专业抓包工具Wireshark
说明:专业到不太会用. 下载: (链接: https://pan.baidu.com/s/1c570YE 密码: pkmr)
- [转]分布式锁-RedisLockRegistry源码分析
前言 官网的英文介绍大概如下: Starting with version 4.0, the RedisLockRegistry is available. Certain components (f ...
- 第十篇---javascript函数this关键字
<script type="text/javascript" charset="utf-8"> //this:this对象是指运行时期基于执行环境所 ...