开发者

Delete same cookie on different domains

开发者 https://www.devze.com 2023-03-08 22:26 出处:网络
In the past we were setting our cookies without the \'domain\' option (using the cookie plugin) e.g: $.cookie(\"blah\", \"1\", {

In the past we were setting our cookies without the 'domain' option (using the cookie plugin) e.g:

$.cookie("blah", "1", {
    expires: 365,
    path: "/"
});

Now we are setting it like:

$.cookie("blah", "1", {
    expires: 365,
    path: "/",
    domain: ".site.com"
});

However the problem is there are 2 cookies with the same name set for users who already have the old cookie on the page.

As a solution, at the point of setting the new cookie I am doing:

$.cookie("blah", null, {
    path: "/"
});

Which should dele开发者_运维知识库te the cookie without the 'domain' option. Otherwise when reading the cookie it could give me the old value as there may be 2 set with the same name.

Do you think this is an ok workaround? I tested it in Firefox and it works fine as I haven't specified the domain part so it shouldn't delete the new cookie, just the old, however I am worried it could happen maybe on older browsers like IE6 or on mobiles (we get a lot of mobile traffic)?

Any guidance would be great!


seems fine :) I believe it should work in every case.

0

精彩评论

暂无评论...
验证码 换一张
取 消