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 ...
随机推荐
- 解决织梦dedecms文档关键字(自动内链)php5.5以上失效的问题 urf-8版本的
找到include/arc.archives.class 在里面需要修改两次地方 在1230行 // 这里可能会有错误 if (version_compare(PHP_VERSION, '5.5.0' ...
- HDU4641 || 6194多校 (后缀自动机-最少出现K次的字串个数 || 恰好出现K次字符串的个数)
http://acm.hdu.edu.cn/showproblem.php?pid=4641 http://acm.hdu.edu.cn/showproblem.php?pid=6194 题意: 开始 ...
- *args and **kwargs
首先要知道, 并不是必须写成*args 和**kwargs. 只有变量前面的 *(星号)才是必须的. 你也可以写成*var 和**vars. 而写成*args 和**kwargs只是一个通俗的命名约定 ...
- PHP操作sqlserver乱码解决
将捕获的参数编码转换为GB2312即可 function ($string){ returen iconv("UFT-8","GB2312//IGNORE",$ ...
- 第2章—装配Bean—自动化装配Bean
自动化装配Bean 2.1.Spring配置可选方案 装配是依赖注入DI的本质,Spring提供了以下三种注入的装配机制: 在XMl中进行显式配置 在java中进行显式配置 隐式的Bean发现机制 ...
- Scala IDEA for Eclipse里用maven来创建scala和java项目代码环境(图文详解)
这篇博客 是在Scala IDEA for Eclipse里手动创建scala代码编写环境. Scala IDE for Eclipse的下载.安装和WordCount的初步使用(本地模式和集群模式) ...
- thumbnailator + webp-imageio-core实现java处理图片支持webp
thumbnailator提供了便捷的图片处理api,webp-imageio-core屏蔽了不同平台webp本地库的差异. <dependency> <groupId>com ...
- scrapyd远程连接配置
安装scrapyd: pip install scrapyd 默认scrapyd启动是通过scrapyd就可以直接启动,bind绑定的ip地址是127.0.0.1端口是:6800,这里为了其他主机可以 ...
- WPF中Label使用StringFormat
1. 在WPF中Label的Content有时内容只需要改变个别数字,而不需要所以内容都修改,这时候就要使用StringFormat, 如: <Label Content="I hav ...
- springMVC流程分析
下面是DispatcherServlet的doDispatch()方法 protected void doDispatch(HttpServletRequest request, HttpServle ...