JS adds a Cookie to get the cookie value to delete the cookie, jscookie
Function setCookie (name, value) {var Days = 30; var exp = new Date (); exp. setTime (exp. getTime () + Days * 24x60*60*1000); document. cookie = name + "=" + escape (value) + "; expires =" + exp. toGMTString (); var strsec = getsec (time); var exp = new Date (); exp. setTime (exp. getTime () + strsec * 1); document. cookie = name + "=" + escape (value) + "; expires =" + exp. toGMTString ();} // read cookiesfunction getCookie (name) {Var arr, reg = new RegExp ("(^ |)" + name + "= ([^;] *) (; | $ )"); if (arr = document. cookie. match (reg) return (unescape (arr [2]); else return null;} // Delete cookiesfunction delCookie (name) {var exp = new Date (); exp. setTime (exp. getTime ()-1); var cval = getCookie (name); if (cval! = Null) document. cookie = name + "=" + cval + "; expires =" + exp. toGMTString ();}
How to Use js to dynamically create, delete, and set values in cookies,
Read the manual by yourself
Baidu w3cschool
How does JS delete a cookie?
Js reads the cookie, js adds the cookie, and js deletes the cookie. The following is an example:
<! Doctype html public "-// W3C // dtd html 4.01 // EN" "www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GB2312"/>
<Title> cookie processing function exercise (I wrote it, not what I think: Improving object-oriented) </title>
<Script language = "JavaScript" type = "text/javascript">
Function addCookie (objName, objValue, objHours) {// Add cookie
Var str = objName + "=" + escape (objValue );
If (objHours> 0) {// when the value is 0, no expiration time is set. When the browser is disabled, the cookie disappears automatically.
Var date = new Date ();
Var MS = objHours x 3600*1000;
Date. setTime (date. getTime () + MS );
Str + = "; expires =" + date. toGMTString ();
}
Document. cookie = str;
Alert ("cookie added successfully ");
}
Function getCookie (objName) {// obtain the cookie value of the specified name
Var arrStr = document. cookie. split (";");
For (var I = 0; I <arrStr. length; I ++ ){
Var temp = arrStr [I]. split ("= ");
If (temp [0] = objName) return unescape (temp [1]);
}
}
Function delCookie (name) {// to delete a cookie with the specified name, you can set its expiration time to a previous time.
Var date = new Date ();
Date. setTime (date. getTime ()-10000 );
Document. cookie = name + "= a; expires =" + date. toGMTString ();
}
Function allCookie () {// read all saved cooki... the remaining full text>