A cookie is a variable stored on a visitor's computer. This cookie is sent whenever a page is requested by the same computer through a browser. You can use JavaScript to create and retrieve the value of a cookie.
Add a cookie
Describe:
Create a new cookie to be managed by the browser!
Parameter description:
Name-Key of the key-value pair, which uniquely marks a value
Value-values of key-value pairs, contents of the cookie Store
Expdays-cookie Expiration Time (active time)
function Setcookie (name, value, expdays) { var expdate = new Date ();//Set cookie expiration date expdate.setdate ( Expdate.getdate () + expdays); Add a cookie document.cookie = name + "=" + Escape (value) + "; expires=" + expdate.toutcstring ();}
Get cookies
Describe:
Based on the name of the parameter, get the value of the corresponding value in the cookie
function GetCookie (name) {//Gets the name in the cookie starting and ending position var start = document.cookie.indexOf (name + "="); if (Start! =-1) { start = start + name.length + 1;//Gets the terminating position of value var end = Document.cookie.indexOf (";", start); C6/>if (end = =-1) end = Document.cookie.length; Intercepts the value of the cookie and returns the return unescape (document.cookie.substring (Start, end)); } Return "";}
Delete Cookies
Describe:
Delete a cookie based on name (set to expire immediately)
function Delcookie (name) { Setcookie (name, "",-1);}
Extended Features:
Pre-agreed, same key, multiple value,value separated by commas (,)
Determine if a value already exists
function Isexistvalue (key, Val) { var value = GetCookie (key); var index = Value.indexof (val); return Index! =-1;}
JS Operation Cookie