从子域中读取Javascript Cookie [英] Reading Javascript Cookies from a subdomain

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

问题描述

在子网域上 - a.test.com - 我想读取.test.com上设定的Cookie。如果我在JS中使用document.cookie,我得到的是a.test.com的cookie。从.test.com读取cookie的语法或路由是什么?

On a subdomain -- a.test.com -- I'm trying to read the cookies set at .test.com. If I use document.cookie in JS, all i'm getting are the cookies from a.test.com. What is the syntax or route to read the cookies from .test.com?

我很确定你可以读取 - 从子域到fqdn - 但是您不能读取fqdn到子域。

I'm pretty certain you can read up -- from sub domain to fqdn -- but you can not read down -- fqdn to sub domain.

谢谢!

推荐答案

test.com example.com设置Cookie时,请确保将Cookie域指定为。test.com.example.com 。

While setting the cookies at test.com example.com, make sure that you specify the cookie domain as ".test.com" ".example.com".

例如:

your_key_name=your_key_value;domain=.example.com;expires=...

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

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