Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Change Cookie

  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change Cookie

    Hello,

    I was wondering if someone could tell me how to change the cookie on this piece of code?

    I'd like it to put a different cookie for each page it's used on.

    Any help would be appreciated.

    Thanks!
    Code:
           /* 
            * COOKIE FUNCTIONS
            */
           
            function createCookie(name, value, days) {
                if (days) {
                    var date = new Date();
                    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                    var expires = "; expires=" + date.toGMTString();
                }
                else var expires = "";
                document.cookie = name + "=" + value + expires + "; path=/";
            }
    
            function readCookie(name) {
                var nameEQ = name + "=";
                var ca = document.cookie.split(';');
                for (var i = 0; i < ca.length; i++) {
                    var c = ca[i];
                    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, 
    
    c.length);
                }
                return null;
            }
    
            function eraseCookie(name) {
                createCookie(name, "", -1);
            }
            
            /* 
             * END COOKIE FUNCTIONS
    Last edited by Inigoesdr; 07-11-2011 at 01:13 AM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,469
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I'm curious as to why you would want a different cookie for each page it's used on.

    Can you describe what you are trying to do? Not that what you're doing is wrong,
    but I think there might be a better way (or a more "normal" way) of doing it.

    Typically, you would have the cookie remember the page number (or name).



    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •