user241674
user241674

Reputation: 31

How to set a cookie for another domain using JavaScript?

Is it possible to set cookie in one domain and access the same in another domain?

Actually I need to set a cookie in A.com page when user clicks a button and then user needs to be redirected to B.com. But the cookies are working for the same domain but not for other domain.

Upvotes: 3

Views: 8382

Answers (3)

arikanmstf
arikanmstf

Reputation: 473

if you have both A.com and B.com, you can simply make a http (or https whatever) request from A to B and put on it whatever you want to pass to B.com . B.com gets the request, saves it serverside, when user enters the B.com, server sends back the data to user.

Upvotes: 0

CoderPi
CoderPi

Reputation: 13211

No. You can only set cookies for the domain your script is currently running on.

Upvotes: 4

Quentin
Quentin

Reputation: 943560

Is it possible to set cookie in one domain and access the same in another domain?

No. That would be a security risk.

Cookies were designed for maintaining state, like user preferences. Would you like Joe Random Evil Site to be able to change your preferences for your Online Banking service?

Upvotes: 3

Related Questions