Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-09-2011, 09:21 PM   PM User | #1
curt3006
New to the CF scene

 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
curt3006 is an unknown quantity at this point
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..
curt3006 is offline   Reply With Quote
Old 07-10-2011, 06:08 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,045
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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).



.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:21 PM.


Advertisement
Log in to turn off these ads.