封裝好的寫入cookie和讀取cookie的代碼cookie
設置cookie編碼
function login(){orm
userForm.logintyp.value='CA';
userForm.usernam.value=o.CertName;
userForm.email.value=o.Email;
SetCookie("CertName", o.CertName);
SetCookie("Email", o.Email);get
}io
//進入頁面後﹐直接進行Chookie檢測﹐若是有記錄相關信息﹐則能夠直接登錄
function chkChookie(){
var CertName = GetCookie("CertName");
var Email = GetCookie("Email");
if(CertName!=null&&Email !=null){
userForm.logintyp.value='CA';
userForm.email.value=Email;
return true;
}else{
return false;
}
}function
封裝cookie expires是用來設置對應cookie的過時時間;escape()用來對特殊字符進行編碼
function SetCookie(name, value){
var Days=30; //此 cookie 被保存 30 天
var exp=new Date();//new Date("December 31, 9998");
exp.setTime(exp.getTime()+ Days*24*60*60*1000);
document.cookie = name + "="+escape(value) +";expires="+ exp.toGMTString();
}email
//get Cookie
function GetCookie(name){
//var Res = eval('/'+_Name+'=([^;]+)/').exec(document.cookie);
var arr=document.cookie.match(new RegExp("(^|)"+name+"=([^;]*)(;|$)"));
if(arr!= null) return unescape(arr[2]); return null;
}im
//del Cookie
function delCookie(name)
{
var exp = newDate();
exp.setTime(exp.getTime() -1);
var cval=getCookie(name);
if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString();
}ember