Get a value example of a cookie
<script language= "Web Effects" type= "Text/javascript" >
<!--
Set two cookies
Document.cookie= "userid=828";
Document.cookie= "Username=hulkwww.111cn.net";
Get cookie String
var Strcookie=document.cookie;
Cut multiple cookies to multiple name/value pairs
var arrcookie=strcookie.split (";");
var userid;
Iterate through the cookie array, processing each cookie on the
for (Var i=0;i<arrcookie.length;i++) {
var arr=arrcookie[i].split ("=");
Find the cookie with the name UserID and return its value
if ("userid" ==arr[0]) {
USERID=ARR[1];
Break
}
}
Alert (userid);
-->
</script>
Cookie Set Expiration Date Example
<script language= "javascript" type= "Text/javascript" >
<!--
Get current time
var date=new date ();
var expiredays=10;
Set date to 10 days later
Date.settime (Date.gettime () +expiredays*24*3600*1000);
Set the UserID and username two cookies to expire after 10 days www.111cn.net
Document.cookie= "userid=828; Username=hulk; Expire= "+date.togmtstring ();
-->
</script>
Delete Cookie Example
<script language= "javascript" type= "Text/javascript" >
<!--
Get current time
var date=new date ();
Set Date to past time
Date.settime (Date.gettime ()-10000);
Remove UserID This cookie
Document.cookie= "userid=828; Expire= "+date.togmtstring ();
-->
</script>
Constructs a generic cookie handler function
<script language= "javascript" type= "Text/javascript" >
<!--
function Addcookie (name,value,expirehours) {
var cookiestring=name+ "=" +escape (value);
Determine whether to set an expiration time
if (expirehours>0) {
var date=new date ();
Date.settime (date.gettime+expirehours*3600*1000);
Cookiestring=cookiestring+ "; Expire= "+date.togmtstring ();
}
document.cookie=cookiestring;
}
function GetCookie (name) {
var Strcookie=document.cookie;
var arrcookie=strcookie.split (";");
for (Var i=0;i<arrcookie.length;i++) {
var arr=arrcookie[i].split ("=");
if (Arr[0]==name) return arr[1];
}
Return "";
}
function Deletecookie (name) {
var date=new date ();
Date.settime (Date.gettime ()-10000);
Document.cookie=name+ "=V; Expire= "+date.togmtstring ();
}
-->
</script>