[英]Javascript Cookie
I have cookies for the domain .forum.mywebsite.com
and for .mywebsite.com
. 我有域名
.forum.mywebsite.com
和.mywebsite.com
。
Is it possible to read the cookie for the .mywebsite.com
domain with javascript from the forum.mywebsite.com
location? 是否可以从
forum.mywebsite.com
位置使用javascript读取.mywebsite.com
域的cookie?
Yes you should be able to read it. 是的,您应该能够阅读它。 Check the following articles
检查以下文章
When the JavaScript set cookies process is invoked, the script either presents the browser with a domain, or a blank value.
调用JavaScript设置cookie进程时,脚本会向浏览器显示一个域或一个空白值。 If no domain is given it is assumed to be the domain of the page ie java-programming.suite101.com in this case.
如果未指定任何域,则在此情况下假定为页面的域,即java-programming.suite101.com。
The JavaScript cookies path, on the other hand, allows the programmer to make sure that the cookie is only valid (sent to the server) for pages in a specific path on the website.
另一方面,JavaScript cookie路径允许程序员确保cookie仅对网站上特定路径中的页面有效(发送到服务器)。 So, specifying a path such as /blog would restrict the cookie to my.domain.com/blog.
因此,指定诸如/ blog之类的路径会将cookie限制为my.domain.com/blog。 If the cookie should be applicable across the whole (sub)domain, then path=/ should be specified.
如果cookie应该适用于整个(子)域,则应指定path = /。
But you will not be able to delete the cookie from the subdomain. 但是您将无法从子域中删除Cookie。 Check this question in SO : Is it possible to delete subdomain cookies?
在SO中检查此问题: 是否可以删除子域cookie?
You can set the domain which has access to a given cookie via adding the cookie attribute value 您可以通过添加cookie属性值来设置有权访问给定cookie的域
domain={domainname};
If {domainname} starts with a leading .
如果{domainname}开头为
.
, any subdomain may access the cookie as well (source: MDC ). ,任何子域也可以访问Cookie(来源: MDC )。
According to RFC 2965 , which is referenced by the W3C spec , the leading .
根据W3C规范所引用的RFC 2965 ,领先
.
shouldn't be necessary, but better safe than sorry ;) 应该没有必要,但是比后悔更安全;)
cookie是作为请求的一部分发送到服务器的,据我所知,它不是可以从客户端访问的(因此javascript无法访问)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.