最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I get the cookies from a subdomain? - Stack Overflow

programmeradmin1浏览0评论

Let's assume I'm on sub.example, how can I get the cookies of .example from there? If that's not possible, is there a workaround like an hack or whatever that redirects to .example and then stores the cookies?

Let's assume I'm on sub.example, how can I get the cookies of .example from there? If that's not possible, is there a workaround like an hack or whatever that redirects to .example and then stores the cookies?

Share Improve this question asked Aug 15, 2017 at 20:14 WayneXMayersXWayneXMayersX 3381 gold badge2 silver badges10 bronze badges 1
  • @SamOnela that doesn't pletely answer my questions. I'm asking also for a workaround of that. – WayneXMayersX Commented Aug 15, 2017 at 20:20
Add a ment  | 

2 Answers 2

Reset to default 11

A web page only has visibility to the cookie with the most specific domain that matches its URL.

So if both example and sub.example both have a cookie named mycookie, a web page in sub.example can only access the one in the subdomain. It hides the cookie in the example domain, and there's no way to access it.

But if there's only a cookie in example, it will be visible to both example and sub.example pages.

When creating a cookie, it defaults to the full domain of the page, but the code can specify a less specific domain. So if sub.example creates a cookie, it will default to domain=sub.example. But the code can override this by putting domain=.example in the cookie explicitly.

More details can be found in The Definitive Guide to Cookie Domains.

The cookie was set as HttpOnly flag, and the browser made me not able to get the cookie for JavaScript.

发布评论

评论列表(0)

  1. 暂无评论