1 Star 0 Fork 1

yanfant/CoreJS

forked from 十里/CoreJS 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
storage.js 2.52 KB
一键复制 编辑 原始数据 按行查看 历史
十里 提交于 2021-03-22 01:29 . update storage.js.
/*(c)http://gitee.com/silis-open/CoreJS*/
(function(win){
win.setCookie = function(key, value, time){
if(time != null)
win.document.cookie = key + "=" + encodeURIComponent(value) + ";expires=" + new Date(new Date().getTime() + time).toGMTString();
else
win.document.cookie = key + "=" + encodeURIComponent(value);
}
win.getCookie = function(key){
var matchs = win.document.cookie.match(key + "=([^;]*)");
if(matchs) return decodeURIComponent(matchs[1]); else return null;
}
win.removeCookie = function(key){
win.document.cookie = key + "=;expires=" + new Date(new Date().getTime() - 31536000000).toGMTString();
}
if(!win.localStorage){
win.localStorage = {
setItem:function(key,value){
win.setCookie("l_" + key, value, 31536000000);
//win.document.cookie = "l_" + key + "=" + encodeURIComponent(value) + ";expires=" + new Date(new Date().getTime() + 31536000000).toGMTString();
},
getItem:function(key){
return win.getCookie("l_" + key);
//var matchs = win.document.cookie.match("l_" + key + "=([^;]*)");
//if(matchs) return decodeURIComponent(matchs[1]); else return null;
},
removeItem:function(key){
win.removeCookie("l_" + key);
//win.document.cookie = "l_" + key + "=;expires=" + new Date(new Date().getTime() - 31536000000).toGMTString();
},
clear:function(){
var matchs = win.document.cookie.match(/l_[^=]+=/g);
if(matchs){
for(var i = 0; i < matchs.length; i++){
var key = matchs[i];
key = key.substring(2, key.length-1);
win.localStorage.removeItem(key);
}
};
}
};
};
if(!win.sessionStorage){
win.sessionStorage = {
setItem:function(key,value){
win.setCookie("s_" + key, value);
//win.document.cookie = "s_" + key + "=" + encodeURIComponent(value);
},
getItem:function(key){
return win.getCookie("s_" + key);
//var matchs = win.document.cookie.match("s_" + key + "=([^;]*)");
//if(matchs) return decodeURIComponent(matchs[1]); else return null;
},
removeItem:function(key){
win.removeCookie("s_" + key);
//win.document.cookie = "s_" + key + "=;expires=" + new Date(new Date().getTime() - 31536000000).toGMTString();
},
clear:function(){
var matchs = win.document.cookie.match(/s_[^=]+=/g);
if(matchs){
for(var i = 0; i < matchs.length; i++){
var key = matchs[i];
key = key.substring(2, key.length-1);
win.sessionStorage.removeItem(key);
}
};
}
}
}
})(window);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/yanfant/CoreJS.git
git@gitee.com:yanfant/CoreJS.git
yanfant
CoreJS
CoreJS
master

搜索帮助