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 ...
随机推荐
- JavaScript DOM编程艺术 笔记(三)函数
函数function 是在你的代码里随时调用的语句 每个函数是个短小的脚本,arguments,传递的参数 function name(arguments){ statements; } functi ...
- bash: wget: command not found
有些VPS执行wget命令下载时,提示-bash: wget: command not found错误,其实这是由于系统中没有安装wget,我们只要执行安装命令安装即可. yum -y install ...
- 1091 N-自守数 (15 分)
// 建一个判断函数,接受两个整形的变量,再通过循环按位判断相等与否,主体函数中调用被调函数,建立一个判断变量.#include <iostream> using namespace st ...
- Go语言目录
为什么学习Go语言 第一章 环境搭建 Windows搭建Go语言环境 第二章 Go语言基础 Go语言介绍 Go语言命名 Go语言内置类型和函数 Go语言特殊函数介绍 Go语言运算符 第三章 Go语言程 ...
- MAVEN打zip包
https://blog.csdn.net/yulin_hu/article/details/81835945 https://www.cnblogs.com/f-zhao/p/6929814.htm ...
- Cisco ISR4400 Netflow 配置模板
flow exporter NAME destination 145.0.1.200 transport udp 9991 export-protocol netflow-v5 flow monito ...
- This operation is not available unless admin mode is enabled: FLUSHDB
报错: This operation is not available unless admin mode is enabled: FLUSHDB 参考内容: https://www.cnblogs ...
- window7 下安卓开发环境搭建
最新Win7下配置搭建安卓开发环境 注意:因为墙的原因 google的更新服务器需要改 hosts 你懂的.. 74.125.237.1 dl-ssl.google.com 不行就VPN ...
- (转)CentOS7安装KVM虚拟机详解
原文:https://github.com/jaywcjlove/handbook/blob/master/CentOS/CentOS7%E5%AE%89%E8%A3%85KVM%E8%99%9A%E ...
- TensorFlow架构与设计:概述
TensorFlow是什么? TensorFlow基于数据流图,用于大规模分布式数值计算的开源框架.节点表示某种抽象的计算,边表示节点之间相互联系的张量. TensorFlow支持各种异构的平台,支持 ...