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:
- 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.