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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post

    Cookie expiration date not being set right?

    Hello all, I need some quick help with one of my scripts.

    It's supposed to set the expiration date of all the cookies on my page for one year, but it's not working.

    I know it's not working because Safari lets you see the expiration date for each cookie set on a page, and it didn't show it for the elements being set on my page.

    I'm using jQuery for this, so heres my one script:

    Code:
    var currentRotation=null;
    
    function checkOrientAndLocation(){
    	if(currentRotation != window.orientation){
    		setOrientation();
    	}
    }
    
    function setOrientation(){
    	switch(window.orientation){
    		case 0:
    			orient = 'portrait';
    			break;
    		case 90:
    			orient = 'landscape';
    			break;
    		case -90:
    			orient = 'landscape';
    			break;
    	}
    	currentRotation = window.orientation;
    	document.body.setAttribute("orient",orient);
    	setTimeout(scrollTo,0,0,1);
    }
    
    $(window).unload(function() { // On page unload
        $('.remember').each(function() { // Save each value to expire in a year
            $.cookie(this.id, this.value, {expires: 365});
        });
        $('.draggable').each(function() { // Save draggable positions
            var draggable = $(this);
            $.cookie(this.id, draggable.css('top') + '_' + draggable.css('left'), {expires: 365});
            $.cookie('disp' + this.id, draggable.css('display'), {expires: 365});
        });
    });
    
    $(function() {
      var val, pos, disp;
      setInterval(checkOrientAndLocation,1000);
      $('.remember').each(function() {
            var val = $.cookie(this.id); // Retrieve value for this element
            if (val) {
                this.value = val;
            }
        }
      );
      $('.draggable').each(function() {
            var pos = $.cookie(this.id); // Retrieve values for this element
            if (pos) {
                pos = pos.split('_');
                $(this).css({position: 'absolute', top: pos[0], left: pos[1]});
            }
            var disp = $.cookie('disp' + this.id);
            if (disp) {
                this.style.display = disp;
            }
        }
       ).touch({animate: false, sticky: false, dragx: true, dragy: true,
            rotate: false, resort: false, scale: false
      });
    });
    There's also a file that sets the basic elements for the cookie, but the expiration date code should be in the file above. Help is very much appreciated.

  • #2
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post
    Bump.

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    browsers limit the lifetime of cookies, one year might be over the limit

  • #4
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post
    Well I'm working in safari exclusively, but I've had cookies set for longer than a year and it usually shows the expiration date it in if you go to Prefs>Advanced>Show Cookies

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by gizmo1650 View Post
    browsers limit the lifetime of cookies, one year might be over the limit
    Nonsense.

  • #6
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post
    Quote Originally Posted by Philip M View Post
    Nonsense.
    Agreed, so any ideas what it might be?

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by pxlcreations View Post
    Agreed, so any ideas what it might be?
    Nope. You would do best to post your question in the jQuery forum.

  • #8
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post
    Ok, thanks.


  •  

    Posting Permissions

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