[Javascript] using a cookie

simeonfosterwillbanks simeon at simeons.net
Fri Aug 27 09:20:40 CDT 2004


hello,

i am trying to grab some information from a cookie.  if i print all cookies via
document.write(document.cookie); i only get the first 3 or 4 stored.  i know
this because i can look at the stored cookies in the internet options.  plus, i
can print all cookies via php.  this is a problem because; i am trying to use
this function to get the information of a cookie not printed to the page.  the
function is returning no information when i use the absent cookie.  if i use it
in conjunction with a cookie printed to the page via
document.write(document.cookie), it will return information.

function readCookie(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 c.substring(nameEQ.length,c.length);
	}
	return null;
}

from: http://www.quirksmode.org/js/cookies.html

any ideas why i can't grab all my cookies via javascript?

thanks,
Simeon


--
http://www.simeons.net - it's fun



More information about the Javascript mailing list