简体   繁体   中英

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?

Nope, that will not work for security reasons.

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?

Due to many people abusing it, most browsers block 3rd party either by default or by the user setting such a preference.

From Cookies :

Each cookie also has a domain and a path. The domain tells the browser to which domain the cookie should be sent. If you don't specify it, it becomes the domain of the page that sets the cookie, in the case of this page www.quirksmode.org. Please note that the purpose of the domain is to allow cookies to cross sub-domains. My cookie will not be read by search.quirksmode.org because its domain is www.quirksmode.org. When I set the domain to quirksmode.org, the search sub-domain may also read the cookie. I cannot set the cookie domain to a domain I'm not in, I cannot make the domain www.microsoft.com. Only quirksmode.org is allowed, in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM