最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I do not know what is the cookie's path? how to find it? - Stack Overflow

programmeradmin1浏览0评论
 function setCookie(name, value)
    {
        var times = 30;
        var exp = new Date();
        exp.setTime(exp.getTime() + times * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + encodeURI(value) + ";expires=" + exp.toUTCString() + ";path=/";       
    }

"path=/" represents cookie's path is what? and if delete "path=/", cookie's path is what?

 function setCookie(name, value)
    {
        var times = 30;
        var exp = new Date();
        exp.setTime(exp.getTime() + times * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + encodeURI(value) + ";expires=" + exp.toUTCString() + ";path=/";       
    }

"path=/" represents cookie's path is what? and if delete "path=/", cookie's path is what?

Share Improve this question edited Jan 15, 2017 at 7:56 Superman asked Jan 15, 2017 at 7:04 SupermanSuperman 2855 silver badges17 bronze badges 6
  • 1 Is it some javascript poem? Regarding path you cannot access it from code – Vinay Commented Jan 15, 2017 at 7:13
  • @Novice, This is js code; I want to find the cookie, where is the cookie? Thanks for your reply – Superman Commented Jan 15, 2017 at 7:25
  • I want to know where the cookie file locates – Superman Commented Jan 15, 2017 at 7:59
  • 1 That's what I am saying friend .While storing cookies by you supply all stuff but when you try to read by using document.cookie it will only give this part name + "=" + encodeURI(value) And path does not refer to your system's path but rather path relative to website.for eg. if cooki is set for path like google/mypony then it will be used only on that page – Vinay Commented Jan 15, 2017 at 8:01
  • Thank you very much! I feel know your mean. you mean that js cookie file can not be found, because it do not store system's path. is this? – Superman Commented Jan 15, 2017 at 8:14
 |  Show 1 more ment

1 Answer 1

Reset to default 4

"path=/" means

path is set, you can access cookie name anywhere in your application/domain (http://localhost or http://example.)

"path=/" is not set means

path is not set, then cookie name is save just for the directory(also include its child directory)
in which current page belongs to, you can't access it on another directory


Check this links

https://developer.mozilla/en-US/docs/Web/API/Document/cookie

http://www.quirksmode/js/cookies.html

发布评论

评论列表(0)

  1. 暂无评论