Reading a Cookie
Question: How do I read a cookie with a given name?
Answer:
To read a cookie cookieName
that has been set
by the SetCookie
function,
you can use the following function:
function ReadCookie(cookieName) {
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName);
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(';',ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
JavaScripter.net.
Copyright
© 1999-2006, Alexei Kourbatov