JavaScript Tutorials Write cookies read cookies and decode cookies
function Writecookie (name, value, hours) {
var expire = "";
if (hours!= null) {
expire = new Date (new Date ()). GetTime () + hours * 3600000);
expire = "; Expires= "+ expire.togmtstring ();
}
Document.cookie = name + "=" + Escape (value) + expire;
}
Read cookies
function Readcookie (name) {
var cookievalue = "";
var search = name + "=";
if (Document.cookie.length > 0) {
offset = document.cookie.indexOf (search);
if (offset!=-1) {
Offset + + search.length;
End = Document.cookie.indexOf (";", offset);
if (end = = 1) end = Document.cookie.length;
Cookievalue = unescape (document.cookie.substring (offset, end)
}
}
return cookievalue;
}
//Read cookies with decoding
function Readcookiedecode (name) {
var Nameeq = name + "=";
var ca = Document.cookie.split (';');
for (var i=0;i < ca.length;i++) {
var c = ca[i];
while (C.charat 0 = = = ') c = c.substring (1,c.length);
if (C.indexof ( Nameeq) = = 0) return decodeuricomponent (c.substring (nameeq.length,c.length));
}
return null;
}