How to get same cookie to control two different folders on same site.
        Posted  
        
            by 
                Incandescent
            
        on Super User
        
        See other posts from Super User
        
            or by Incandescent
        
        
        
        Published on 2011-01-14T05:13:10Z
        Indexed on 
            2011/01/14
            5:55 UTC
        
        
        Read the original article
        Hit count: 438
        
cookies
I am using the below cookie javascript to run a background color changer on my site. I want to also use it for the background color of my forum which is in a separate folder (http://lightbulbchoice.com/forum). I currently have it working on both the site and forum but you have to set each separately, i.e., each is setting it's own cookie.
How do I get the forum to locate the main site cookie and not set it's own?
// Cookie Functions - Second Helping (21-Jan-96) // Written by: Bill Dortch, hIdaho Design // The following functions were released to the public domain by him. function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); }
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) ==arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; }
function SetCookie (name, value) { var argv = SetCookie.arguments; var argc = SetCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : ""); } // --> </script>
© Super User or respective owner