views:

906

answers:

1

How can you set a cookie on a different Domain that is calling my site with a javascript call? It works in FF3, but not in IE6.

My server is called from a javascript tag on a seperate site and domain. The result returns javascript that populates their page with data (it's a widget). I am trying to set a cookie using domain=".mydomain.com" and path="/". It works for Firefox, but won't work in IE. It works fine in IE if I test the javascript call from my own domain.

Does anyone know how to get cross domain cookie setting to work in IE, using Rails?

A: 

As long as your server is setting a cookie within its own domain or from a subdomain of its domain, this should work

cookies[cookie_name] = {
   :value => 'a value',
   :expires => 1.year.from_now,
   :domain => 'domain.com'
 }

It won't work for any other domains.

To get this to work in IE6 you may need a valid P3P policy header

Something like this sent as a header should do it:

headers["p3p"] = 'CP="CAO PSA OUR"'
DanSingerman
that is how I set it: cookies[cookie_name] = { :value => 'x', :expires => 1.day.from_now, :domain => '.mydomain.com' }And yes, it does work for firefox. I actually thought it wouldn't but it does. But in IE, I see it trying to set the header but the cookie is not there after their page loads.
Zack
How do you know? Can you post your code which is telling you the cookie is not there?
DanSingerman
I'm using Fidler to see the calls to my domain and look at the header responses. I am using IE Developer toolbar to look at the cookies on my page (and theirs) but it does not exist. I also try to grab the cookie when I return to my site and it does not exist. In FF everything works fine.
Zack
Who's domain are you trying to set it in? The domain of the response you are sending, or the domain of the page that is calling your javascript?
DanSingerman