设置Cookie路径 [英] Set Cookie Path
问题描述
我有一个javascript cookie,尽管我在不同目录中都有页面。默认页面上设置的cookie的路径为 /,而另一个目录中设置的cookie的路径为 / example
I have a javascript cookie which works although I have pages in different directories. The cookie set on the default page has a path "/" while the cookie set in another directory has a path "/example"
我知道很多人问过很多时代,但我自己做不到。我制作了一个Cookie代码,该代码在过去三个月中一直有效。我不想弄乱它。谁能帮助我在Cookie代码中添加设置路径 /?
I know many people have asked this many times but I can't do it by myself. I made a cookie code that actually works from the past three months. I don't want to mess it up. Can anyone help me add a set path "/" to my cookie code? Thanks in advance.
我的代码是:
<script language="JavaScript">
function SetCookie(cookieName,cookieValue) {
var today = new Date();
var expire = new Date();
var nDays=365
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue)
+ ";expires="+expire.toGMTString();
}
</script>
推荐答案
通过在以下内容的末尾添加以下内容来指示路径函数 SetCookie中的cookie字符串:
Indicate the path by adding the following to the end of the cookie string in function "SetCookie":
"; path=/";
http://www.quirksmode.org/js/cookies.html#doccookie
这篇关于设置Cookie路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!