js cookie js作成cookie期限切れ時間設定
944 ワード
// Cookie
function GetCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
// Cookie
//name:cookie value:cookie
function SetCookie(name, value) {
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + 60 * 2000);// 2
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf(";", offset);
if (endstr == -1) endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
本人はとても役に立つと思います. マーキングしてください