Sal
Sal

Reputation: 3269

Setting a cookie in a different path, relative to the user's current URL path

I'm trying to set a cookie in a users session, relative to a path different than where the user currently is. (That is, the path I want the cookie to be relative to is "/", where the user is currently in in "/_CGI". I'm trying the following, but it's not working.

<script type="text/javascript">
    $(document).ready(setMobileBrowsingCookie());

    function setMobileBrowsingCookie()
    {
        document.cookie = "WF_BROWSING_MODE=MOBILE; path=/";
    }
</script>

From my Chrome developer console, I can see the cookie being set when I remove the optional path=/ arg, but if I remove it, the cookie will be set relative to the CGI handle /_CGI. Is the path arg not being used correctly?

Upvotes: 0

Views: 1516

Answers (1)

Mike Brant
Mike Brant

Reputation: 71384

You need to set the cookie expiration as well.

document.cookie = 'WF_BROWSING_MODE=MOBILE; expires=Fri, 30 Aug 2012 20:47:11 UTC; path=/'

Upvotes: 2

Related Questions