开发者

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

开发者 https://www.devze.com 2023-03-12 04:30 出处:网络
I tried it with jQuery: $.cookie(\'test\', \'value\', { expires: 7, path: \'/\', domain: \'test.com\'开发者_如何学Python });

I tried it with jQuery:

$.cookie('test', 'value', { expires: 7, path: '/', domain: 'test.com'开发者_如何学Python });

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消