Several common methods of manipulating cookies in JS
* The concept of domain exists in cookies, using path and domain to differentiate
Get cookies
functionGetCookie (c_name) {if(document.cookie.length>0) {console.log (document.cookie); C_start=document.cookie.indexof (c_name + "="); if(c_start!=-1) {c_start=c_start + c_name.length+1; C_end=document.cookie.indexof (";", c_start); if(c_end==-1) c_end=document.cookie.length; returnunescape (document.cookie.substring (c_start,c_end)); } } return"";}
Set cookies
function setcookie (c_name,value,expiredays) { var cookiestr = ""; var exdate=New Date (); Exdate.setdate (exdate.getdate ()+expiredays); = c_name+ "=" +escape (value) + ((expiredays= =null)? "" : "; expires= "+exdate.togmtstring ()) +";p ath=/";} // Because of the concept of the domain of the cookie, and here to not distinguish the domain, to obtain the value of the cookie, so here is the unified path path=/;
Delete Cookies
1.
function Delete_cookie (name, path, domain) { if(get_cookie (name)) { = name + "=" +
? ";p ath=" +path: ") + (domain)?"; domain= "+domain:" ") + "; expires=thu, 1970 00:00:01 GMT ";} }
2.
function Delete_cookie (name) { = name + ' =; expires=thu, 1970 00:00:01 GMT; ;}
3.
function Delcookie (c_name) { varnew Date (); -1); var cval=GetCookie (c_name); if (cval!=null) document.cookie= c_name + "=;expires=" +
Reference: http://www.w3schools.com/js/js_cookies.asp
Cookie operation in JS