使用javascript设置跨子域cookie
我应该如何为这些函数添加域支持?我想实现将 .example.com 声明为域,以便可以跨 example.com 的所有子域读取 cookie。在当前形式中,由于未设置域,因此只能从 www.example.com 读取
How should I add domain support to these functions? I want to achieve that .example.com is declared as domain, so that the cookies can be read across all subdomains of the example.com. In its current form since domain is not set, it can only be read from www.example.com
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是有关如何在域中共享 Cookie 的链接:
https://www.thoughtco。 com/javascript-by-example-2037272
它涉及设置 cookie 字符串的域属性,例如:
此 cookie 现在应该可供 example.com 的所有子域(如 login.example.com)访问
Here is a link on how to share cookies amongst a domain:
https://www.thoughtco.com/javascript-by-example-2037272
It involves setting the domain attribute of the cookie string like:
This cookie should now be accessible to all sub domains of example.com like login.example.com
就我而言,我们需要设置一个可以跨 .com 子域工作的 cookie:
这可能不适用于 .co.uk 等,但可以使用原理
In my case we needed to set a cookie that would work across our .com subdomains:
This might not work for .co.uk etc but the principle can be used