//Set CookiesfunctionSetcookie (name,value,expires,path,domain,secure) {varCookieName = encodeURIComponent (name) + ' = ' +encodeURIComponent (value); if(ExpiresinstanceofDate) {CookieName+ = '; expires= ' +expires; } if(path) {CookieName+ = ';p ath= ' +path; } if(domain) {cookiename+ = ';d omain= ' +domain; } if(Secure) {CookieName+ = '; Secure= ' +true; } document.cookie=CookieName;}//Expiry Timefunctionsetcookiedate (day) {varDate =NULL; if(typeofDay = = ' number ' && Day > 0) {Date=NewDate (); Date.setdate (Date.getdate ()+Day ); }Else{ Throw NewError (' The number of days you pass is illegal, must be a number and greater than 0 '); } returndate;} Setcookie (' User ', ' Little Fly ', Setcookiedate (7)); Setcookie (' URL ', ' baidu.com ', setcookiedate (7)); Setcookie (' Email ', ' [email protected] ', Setcookiedate (7));//Get CookiesfunctionGetCookie (name) {varCookieName = encodeURIComponent (name) + ' = '; varCookiestart =document.cookie.indexOf (cookiename); varCookievalue =NULL; if(cookiestart>-1){ varCookieend = Document.cookie.indexOf ('; '), Cookiestart); if(Cookieend = =-1) {Cookieend=document.cookie.length; } cookievalue= decodeURIComponent (document.cookie.substring (Cookiestart +cookiename.length,cookieend)); } returnCookievalue;} Alert (GetCookie (' email '));
JavaScript settings and get cookie values