Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

it's possible to set a cookies to another domain with javascript?

I tried it with jQuery:

$.cookie('test', 'value', { expires: 7, path: '/', domain: 'test.com' });

but it won't work.

it's possible to do?

like image 775
MissCc Avatar asked Jun 10 '11 12:06

MissCc


People also ask

Is it possible to set cookie to another domain?

Cookies that are stored and accessed under a specific domain cannot be accessed from a page hosted on another domain. Therefore, the cookie data has to be passed along when leaving one domain and going to the other one.

Can JavaScript access cookies from different domain?

You can't. The only cookies you can read with client side JavaScript are those belonging to the host of the HTML document in which the <script> is embedded.


2 Answers

Nope, that will not work for security reasons.

like image 125
alex Avatar answered Sep 23 '22 21:09

alex


It is not possible to do due to security reasons.

if you are in control of the 2nd domain there are some options to share your cookies described already here: What's your favorite cross domain cookie sharing approach?

like image 35
GeertvdC Avatar answered Sep 22 '22 21:09

GeertvdC