日前看到一个别人总结的读写Cookie的函数想想反正自已也会用得着随手Copy了希望新手拿去用的时候可以更好的做好项目^_^
function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = okieindexOf (; offset)
if (endstr == )
endstr = okielength;
return unescape(okiesubstring(offset endstr))
}
function SetCookie(name value)
//设定Cookie值
{
var expdate = new Date()
var argv = SetCookiearguments;
var argc = SetCookieargumentslength;
var expires = (argc > ) ? argv[] : null;
var path = (argc > ) ? argv[] : null;
var domain = (argc > ) ? argv[] : null;
var secure = (argc > ) ? argv[] : false;
if(expires!=null) expdatesetTime(expdategetTime() + ( expires * ))
okie = name + = + escape (value) +((expires == null) ? : (; expires=+ expdatetoGMTString()))
+((path == null) ? : (; path= + path)) +((domain == null) ? : (; domain= + domain))
+((secure == true) ? ; secure : )
}
function DelCookie(name)
//删除Cookie
{
var exp = new Date()
expsetTime (expgetTime() )
var cval = GetCookie (name)
okie = name + = + cval + ; expires=+ exptoGMTString()
}
function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + =;
var alen = arglength;
var clen = okielength;
var i = ;
while (i < clen)
{
var j = i + alen;
if (okiesubstring(i j) == arg)
return GetCookieVal (j)
i = okieindexOf( i) + ;
if (i == ) break;
}
return null;
}