JavaScript Write cookies
| The code is as follows |
Copy Code |
function Setcookie (C_name,value,expiredays,path) { var exdate=new Date (); Exdate.setdate (Exdate.getdate () +expiredays); document.cookie=c_name+ "=" +escape (value) + ((expiredays==null)? "": "; expires=" +exdate.togmtstring ()) + ";" + ((path==null)? "": "Path=" + Escape (path)); } Setcookie ("Qiufeng", "Www.111cn.net", 24); |
JavaScript Read cookies
| code is as follows |
copy code |
function GetCookie (c_name) { if (document.cookie.length>0) { C_start=document.cookie.indexof (c_name + "="); if (c_start!=-1) { C_start=c_start + c_name.length+1; C_end=document.cookie.indexof (";", C_start); if (c_end==-1) c_end=document.cookie.length; Return unescape (document.cookie.substring (c_start,c_end)); } } Return ""; } |
JavaScript Delete Cookies
| The code is as follows |
Copy Code |
function Delcookie (name) { var date = new Date (); Date.settime (Date.gettime ()-10000); Document.cookie = name + "=A;" Expires= "+ date.togmtstring () +";p ath=* "; } |
JavaScript clears all Cookies
| The code is as follows |
Copy Code |
function Removecookie () { var cookie = document.cookie.split (";"); for (var i in cookie) { Delcookie (Cookie[i].substring (cookie[i].indexof ("="), 0)); } } |
Note: For the two-level domain name is a cookie can not be set or deleted, we can set the domain name 111cn.net can be.
Setcookie ("Qiufeng", "111cn.net", 24);
This can be read in such as qq.111cn.net domain name to this cookie oh, if set to
Setcookie ("Qiufeng", "Www.111cn.net", 24);
Then qq.111cn.net domain name can not access this cookie Oh, the same delete and query is the same OH.