从其他路径检索Cookie [英] Retrieve a cookie from a different path

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

问题描述

我当前的文档URL是http://127.0.0.1/foo,我需要为http://127.0.0.1/bar更改cookie的值. document.cookie为空,因为文档的URL为foo. 目前,我只想读取cookie值. 有任何线索吗?

My current document URL is http: //127.0.0.1/foo and I need to change the value of a cookie for http: //127.0.0.1/bar. document.cookie is empty because document's URL is foo. For the moment, I just want to read the cookie value. Any clue?

推荐答案

创建cookie时,如果将路径设置为"/"而不是"foo",则可以在域中的任何位置读取它,包括'/foo','/bar'等

When you create the cookie, if you set the path to '/' instead of 'foo' you will be able to read it anywhere on the domain, including '/foo', '/bar', etc.

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

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