A: Where does the cookie find the write success in the browser?
Second: How to write with JS
functionAddcookie (name,value,expirehours) {varcookiestring=name+ "=" +escape (value) + "; path=/"; //determine if the expiration time is set if(expirehours>0){ varDate=NewDate (); Date.settime (Date.gettime ()+expirehours*3600*1000); Cookiestring=cookiestring+ "; expires=" +date.togmtstring ();//expires Specifies the lifetime of the cookie, by default the cookie is present, and the value they store exists only during the browser session, and the values are lost when the user launches the browser. If you want a cookie to exist for a period of time, set the Expires property to a future expiration date. } document.cookie=cookiestring;}
Addcookie (' username ', ' Wei ', 12)
Three: How to read and write
function GetCookie (name) { var strcookie=document.cookie;//You can use Console.log () print in the console to view var arrcookie=strcookie.split (";" ); for (var i=0;i<arrcookie.length;i++) { var arr=arrcookie[i].split ("="); if(arr[0]==name)return unescape (arr[1]); } return NULL ;}
Get (' Wei ')
Four: How to delete
function Delcookie (name) {// Delete cookie varnew Date (); -1); var cval=GetCookie (name); if (cval!=null) document.cookie= name + "=" +cval+ "; path=/;expires= "+exp.togmtstring ();}
Delcookie (' Wei ')
Use of cookies in the Web