Javascript Cookie [英] Javascript Cookie

查看:127
本文介绍了Javascript Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有域名 .forum.mywebsite.com .mywebsite.com 的Cookie。 p>

可以使用javascript从中读取 .mywebsite.com forum.mywebsite.com 位置?

解决方案

是的,您应该能够阅读。检查以下文章


当JavaScript设置cookies
进程被调用时,脚本
会向浏览器显示域或
a空值。如果没有给定域
,则假定它是
页面的域,即
java-programming.suite101.com在这个
情况下。



另一方面,
上的JavaScript cookie路径允许程序员
确保cookie仅对
有效(发送到服务器)
在网站的特定路径。因此,
指定一个路径,例如/ blog将
限制cookie为
my.domain.com/blog。如果cookie
应该适用于整个
(子)域,那么path = /应该是
指定的。





  1. JavaScript Cookie

  2. 使用Javascript Cookie

但是您将无法从子域中删除cookie。请在SO中检查此问题:是否可以删除子域名Cookie?


I have cookies for the domain .forum.mywebsite.com and for .mywebsite.com.

Is it possible to read the cookie for the .mywebsite.com domain with javascript from the forum.mywebsite.com location?

解决方案

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. If no domain is given it is assumed to be the domain of the page i.e. java-programming.suite101.com in this case.

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. So, specifying a path such as /blog would restrict the cookie to my.domain.com/blog. If the cookie should be applicable across the whole (sub)domain, then path=/ should be specified.

  1. Javascript Cookies
  2. Using Javascript Cookies

But you will not be able to delete the cookie from the subdomain. Check this question in SO : Is it possible to delete subdomain cookies?

这篇关于Javascript Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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