Simple Method for reading and writing cookies using js (recommended), recommended for reading and writing cookies using js
When the data security requirements are not very high, we can directly use js to read and write cookies, which is more convenient.
The Code is as follows:
/* Function: Save the cookie function parameters: name, cookie name; value, value */function SetCookie (name, value) {var Days = 30*12; // cookie will be saved for one year var exp = new Date (); // get the current time exp. setTime (exp. getTime () + Days * 24*60*60*1000); // change to document in milliseconds. cookie = name + "=" + escape (value) + "; expires =" + exp. toGMTString ();}/* function: Obtain the cookie function parameter: name, cookie name */function getCookie (name) {var arr = document. cookie. match (new RegExp ("(^ |)" + name + "= ([^;] *) (; | $)"); If (arr! = Null) {return unescape (arr [2]);} else {return null ;}/ * function: delete cookie function parameter: name, cookie name */function delCookie (name) {var exp = new Date (); // The current time exp. setTime (exp. getTime ()-1); var cval = getCookie (name); if (cval! = Null) document. cookie = name + "=" + cval + "; expires =" + exp. toGMTString ();}
The simple method (recommended) for reading and writing cookies using js is all the content shared by Alibaba Cloud xiaobian. I hope to give you a reference and support for the customer's house.