Jquery cookie插件不工作的Firefox [英] Jquery cookie plugin not working for Firefox

查看:111
本文介绍了Jquery cookie插件不工作的Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请观看这个小提琴: 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 });
    });
});

输入和点击保存一个列表将被创建和存储cookie。问题是,我的xp系统上的firefox的最新版本不持有cookie。这是奇怪的,因为在工作中,我也有最新版本的Firefox on xp,但在那里,工作正常。

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?

推荐答案

我也有这个问题。我的解决方案是设置路径。

I had this problem also. My solution was to set the path.

$.cookie('cookieName','value',{ expires: 7, path: '/'});

而不是

$.cookie('cookieName','value',{ expires: 7 });

看起来你在一个cookie上设置路径,而不是另一个。

It looks like you set the path on one cookie, but not the other.

这篇关于Jquery cookie插件不工作的Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆