Reputation: 4212
Please take a look at this fiddle: Jsfiddle
$(document).ready(function() {
var cookie = $.cookie('myDemoCookie');
// If the cookie has been set in a previous page load, show it in the div directly:
if (cookie){
var values = $.parseJSON(cookie);
var li;
for (var v in values) {
li = $('<li><a href="' + values[v]+ '">' + values[v] + '</a></li>');
$('.jq-text').append(li).show();
}
}
$('.fields a').click(function(e) {
e.preventDefault();
var text = $('#inputBox').val();
var values = $.parseJSON($.cookie('myDemoCookie')) || [];
values.push(text);
$.cookie('myDemoCookie',JSON.stringify(values),{expires: 7, path: '/' });
$(".jq-text").append('<li><a href="' + text + '">' + text + '</a></li>');
});
$('#form1').submit(function(e){ e.preventDefault(); })
$('.jq-text').on('click', 'li', function(e) {
e.preventDefault();
var values2 = [];
$(this).remove();
$(".jq-text li").each(function(i, item) {
values2.push($(item).text());
});
$.cookie('myDemoCookie', JSON.stringify(values2), { expires: 7 });
});
});
If you put something in the input and click save a list wil be created and stored with cookie. The problem is that the latest version of firefox on my xp system does not hold the cookie. Which is weird because at work I also have the latest version of Firefox on xp, but over there verything works fine.
Im kinda troubled about this because I did not play with the settings, so this means that other people(/visitors) which have the same version could experience the same thing. What could be the cause of this 'strange' behavior?
Upvotes: 2
Views: 2387
Reputation: 176
I had this problem also. My solution was to set the path.
$.cookie('cookieName','value',{ expires: 7, path: '/'});
instead of
$.cookie('cookieName','value',{ expires: 7 });
It looks like you set the path on one cookie, but not the other.
Upvotes: 3