Beverleyh
08-25-2010, 03:22 PM
I'm using a jQuery cookie to switch some special effects on and off - here's the code;
// Cookie - turn special effects off/on switch
jQuery('#fxoff').click(
function () {
jQuery('#fxoff').css({'display':'none'});
jQuery('#fxon').css({'display':'block'});
// do stuff - hide all effects
jQuery.cookie('fx', 'off', { expires: 7 });
}
);
jQuery('#fxon').click(
function () {
jQuery('#fxoff').css({'display':'block'});
jQuery('#fxon').css({'display':'none'});
// do stuff - show all effects
jQuery.cookie('fx', 'off', { expires: -1 });
}
);
var fx = jQuery.cookie('fx');
if (fx == 'off') {
jQuery('#fxoff').css({'display':'none'});
jQuery('#fxon').css({'display':'block'});
// do stuff - hide all effects
};
The #fxoff and #fxon switches appear on all pages of my site including the ones in sub-folders.
If the switch is activated on the home page, the cookie is recognised across the whole site and shows on or off accordingly on every page. Perfect!
BUT If the switch is pressed on a page in a subfolder, the cookie is only recognised on pages in that subfolder and doesnt filter backwards back to the root level.
I tried setting path:'/' but it doesnt seem to have any impact.
I'd like the cookie to be set, recognised and deleted from any page, no matter what level it's at (site-wide recognition).
Can anybody please offer assistance? What am I missing with the path?
// Cookie - turn special effects off/on switch
jQuery('#fxoff').click(
function () {
jQuery('#fxoff').css({'display':'none'});
jQuery('#fxon').css({'display':'block'});
// do stuff - hide all effects
jQuery.cookie('fx', 'off', { expires: 7 });
}
);
jQuery('#fxon').click(
function () {
jQuery('#fxoff').css({'display':'block'});
jQuery('#fxon').css({'display':'none'});
// do stuff - show all effects
jQuery.cookie('fx', 'off', { expires: -1 });
}
);
var fx = jQuery.cookie('fx');
if (fx == 'off') {
jQuery('#fxoff').css({'display':'none'});
jQuery('#fxon').css({'display':'block'});
// do stuff - hide all effects
};
The #fxoff and #fxon switches appear on all pages of my site including the ones in sub-folders.
If the switch is activated on the home page, the cookie is recognised across the whole site and shows on or off accordingly on every page. Perfect!
BUT If the switch is pressed on a page in a subfolder, the cookie is only recognised on pages in that subfolder and doesnt filter backwards back to the root level.
I tried setting path:'/' but it doesnt seem to have any impact.
I'd like the cookie to be set, recognised and deleted from any page, no matter what level it's at (site-wide recognition).
Can anybody please offer assistance? What am I missing with the path?