views:

522

answers:

1

I know there are already a few threads available here on this subject but I want others' opinion on this.

There are two ways to set/read the cross domain cookies:

  1. Creating IFrame on A.com pointing to a page on B.com which creates the cookie and pass that information by creating another IFrame on B.com side pointing to A.com, either using window.name or in location.href.hash
  2. A.com page makes a XHR/JSONP call to B.com web service/page that has the following headers and it also sets up the cookie and returns the value.

AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"")

As we don't have postMessage available across all the browsers, I believe we have to go with one of the cases mentioned above.

My question is which is a better way (cleaner) and why to implement for cross browser. Using any other JS framework is out of scope of this discussion. If there's another better way, please mention here!

Thank you for your intelligent input in advance! :)

+1  A: 

Take a look at EasyXDM. It's a library which wraps cross-browser quirks and provides an easy-to-use API for communicating in client script between different domains using the best available mechanism for that browser (e.g. postMessage if available, other mechanisms if not).

Caveat: you need to have control over both domains in order to make it work (where "control" means you can place static files on both of them).

Justin Grant
Thanks for your answer. I had tested calling a third party (different domain) java script and which sets up the cookie (on that domain) and same value be returned with a call back function. And that worked well. Only caveat was to have P3P policy on that third party domain.
Rac123

related questions