おもちゃjavascript:cookie管理
1146 ワード
;(function(window, undefined){
var CookieUtil = window.CookieUtil = window.CookieUtil || {};
var doc = window.document;
// name Cookie
CookieUtil.read = function(name){
// Cookie
if(doc.cookie.length <= 0){
return null;
}
// cookie
var cookies = doc.cookie.split(';');
var size = cookies.length, i, c;
// cookie
for(i = 0; i < size; i++){
c = cookies[i].split('=');
// cookie, trim, cookie
if($.trim(c[0]) == name){
return unescape(c[1]);
}
}
return null;
};
// name, value Cookie , timeout
CookieUtil.write = function(name, value, timeout){
var flg = timeout === undefined;
var exp = flg ? 0 : timeout;
//
var expires = new Date();
expires.setSeconds(expires.getSeconds() + exp);
// Cookie
doc.cookie = name + '=' + escape(value) + (flg ? '' : (';expires=' + expires.toGMTString()));
};
// name Cookie
CookieUtil.remove = function(name){
CookieUtil.write(name, null, -1);
};
})(window);
著作権声明:本文はブロガーのオリジナル文章で、ブロガーの許可なしに転載してはいけません.