修正javascript的SetCookie

修正流行的Cookie操作javascript.
 
发现下载的javascript 不支持一下操作:
主要是 expires 不能 等于 -1
SetCookie("JOSSO_SESSIONID","hello","-1","/",".jteam.cn");
document.write('GetCookie ("JOSSO_SESSIONID")='+GetCookie ("JOSSO_SESSIONID"));
 
经过修正后的javascript :
function SetCookie (name, value) { 
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null && expires>=0) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null || expires < 0) ? ((expires==-1)?"; expires=-1":"") : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}

你可能感兴趣的:(修正javascript的SetCookie)