Titanium 7
Titanium 7

Reputation: 68

Set Cookie Path

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"

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.

My code is:

    <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>

Upvotes: 1

Views: 3654

Answers (1)

Amiga500Kid
Amiga500Kid

Reputation: 438

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

Upvotes: 4

Related Questions