使用javascript设置跨子域cookie [英] setting cross-subdomain cookie with javascript

查看:557
本文介绍了使用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

推荐答案

这是一个链接关于如何在域名之间共享cookie:

Here is a link on how to share cookies amongst a domain:

https://www.thoughtco.com/javascript-by-example-2037272

它涉及设置cookie字符串的domain属性:

It involves setting the domain attribute of the cookie string like:

document.cookie = "myValue=5;path=/;domain=example.com";

此cookie现在应该可以访问example.com的所有子域,例如login.example.com

This cookie should now be accessible to all sub domains of example.com like login.example.com

这篇关于使用javascript设置跨子域cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆