• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 718
  • Last Modified:

How can javascript read cookie cross-domain?

Dear experts,
I have following requirement:
1. I have www.mydomain.com website,
2. I have put javascript in the mydomain.com page;
3. When user access mydomain.com, the javascript is loaded to the user's browser;
4. the javascript should access some cookies which set by www.otherdomain.com

How can i implement that, or is there any workaround solution to do that?

2 Solutions
You cannot do what you propose.  It would be a huge security risk and no browser is ever going to permit it.

If you control both domains, then you could put scripting on the target page to fetch the cookie and pass it server side but you would be begging to be hacked.

matiascxAuthor Commented:
Hi, Cd,
Thanks for your response.
It is a little depressed for me to hear about that.
Can you give more explaination on your proposal?
I can not understand. If the both domain is under my control, how to implement that?
If the otherdomain.com is not under my control, is it possible to read the cookie via the js in mydomain.com?
I am invstigating possible solutions for that scenario.

Thanks again.
Dave BaldwinFixer of ProblemsCommented:
Because of security restrictions in modern browsers, you are not allowed to read the cookies belonging to someone else or some other domain.  Basically, cookies from another domain are none of your business and you have no rights to view them.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now