JavaScript - Cookie set and get on different domains

Asked By John Hey on 09-May-06 11:33 AM
Hi
I am trying to set a cookie from a page in domain www.abcd.com and I want to read this Cookie in a page of www.123.com (different domain).
I fail all the time, is this possible to do that? if yes ,how can I cross domains?
below is my sample code:
****************************************************
 var today = new Date(); 
 var cookie_expire_date = new Date(today.getTime() + (2 * 7 * 86400000)); 
 Set_Cookie("ifsize",sHeight,cookie_expire_date,"/" , false );
 function Set_Cookie(name,value,expires,path,domain,secure) {
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires.toGMTString() : "") +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
}  
***************************************************
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;
} 
thanks for your help and reply.

Not Possible

Asked By F Cali on 09-May-06 11:40 AM
As far as I know, you cannot set the cookie of another domain mainly due to security reasons.  Here's a link that may help:
http://www.ciac.org/ciac/bulletins/i-034.shtml
"The value of DOMAIN_NAME is limited such that only hosts within the indicated subdomain may set a cookie for that subdomain and the subdomain name is required to contain at least two or three dots in it."

I don't have problem to set cookies from domain,

Asked By John Hey on 09-May-06 12:03 PM
because I have access to both domains,
but my question is that can I read a cookie whick was set by another domain.
Or in a simple way ,assume that you already have a cookie from any domain saved  in your
local machine, can I read it regardless which domain has set that cookie?

No, you cannot

Asked By Robbe Morris on 09-May-06 01:41 PM
Browser security doesn't "know" that you have control of both domains.
The browser will only ever transmit
Asked By Peter Bromberg on 09-May-06 02:17 PM
cookies that are from the domain that it is making a request to.
cross domain cookies
Asked By mv ark on 10-May-06 02:49 AM
Check this link on Sharing Cookies Across Domains: http://www.15seconds.com/issue/971108.htm