I use the jQuery cookie plugin for storing cookies, with the following code I can save a Cookie for 7 days, but it only saves it for the page its created on. I want the cookie to be available for the whole website.
$.cookie('basket',basket,{ expires: 7 });
I tried to set a path, but that didn't seem to work
$.cookie('basket',basket,{ expires: 7, path:'/' });
full code: this works fine, but it only saves the cookie for the current page
function add_to_basket(id,title){ if($.cookie('basket')){ basket=$.cookie('basket'); var basket_array = basket.split(','); var index = jQuery.inArray(id,basket_array); if(index > -1){ return false; }else{ basket+=','+id; $.cookie('basket',basket,{ expires: 7 }); } }else{ basket=id; console.log(basket); $.cookie('basket',basket,{ expires: 7 }); }
A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
When the Add Cookie Button is clicked, the respective jQuery event handler is executed which saves the value of the Name TextBox to browser Cookie using the $. cookie function. The $. cookie function accepts two parameters, first the Name (Key) of the Cookie and second the Value to be stored in the Cookie.
If this is the case, then you can actually check if a user has enabled cookies or not using the following straightforward jQuery snippet: $(document). ready(function() { var dt = new Date(); dt. setSeconds(dt.
I just had the same problem. I fixed it by always specifying the path when writing the cookie.
$.cookie('basket', value, { path: '/' })
This is an issue with the jquery cookie plugin. It will default to the path of the current page.
In the plugin file change:
config.defaults = {};
to
config.defaults = {path:'/'};
from https://github.com/carhartl/jquery-cookie/issues/2#issuecomment-790288
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With