This article mainly introduces the JS settings to obtain cookies, a friend in need can refer to the
Combining the JavaScript authority guide with the data collected on the Web during project development, two methods of setting up and getting cookies were sorted out. Code as follows: <script> //Set cookie method one function Setcookie (name,value) { var exp = new Date (); Exp.settime (Exp.gettime () + 1*60*60*1000);/valid for 1 hours Document.cookie = name + "=" + Escape (value) + "; expires=" + Exp.togmtstring (); } //* When accessing cookies, it is generally necessary to encode the characters that are easily injected, the corresponding decoding when getting cookies, there are many ways of encoding, there is time to write a blog about encoding and decoding/ / /Set Cookie method two direct storage cookies Document.cookie = "homepage = http://www.jb51.net"; /*------------------------------------------------------------------------------------------------ -------/ //Cookies function method One functions GetCookie (name) { var arr = Document.cookie.match (New RegExp ("(^|)" +name+ "= ([^;] *)(;|$)")); if (arr!= null) return unescape (arr[2)); return null; } //Fetch Cookies function Method two function GetCookie (key) {if (key==null) return null; if (Object.prototype.toString.call (key) = = ' [Object String] ' | | ObjecT.prototype.tostring.call (key) = = ' [object number] ') {var arrstr = Document.cookie.split (";"); for (var i= 0;i<arrstr.length;i++) {var temp = arrstr[i].split ("="); if (Temp[0]==key) return unescape (temp[1]); return null; return null; } </script> When learning a lot of JS methods encountered will not be on the Internet to find information, until mastered.