jQuery $ .cookie(domain :)导致无法设置Cookie [英] JQuery $.cookie (domain:) causing cookie not to set

查看:465
本文介绍了jQuery $ .cookie(domain :)导致无法设置Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,下面的代码根据单击的链接ID(即值)设置Cookie,这可行,但是需要做什么来设置域,我已经阅读了如何通过在值中设置域来做到这一点.我设置了domin,它根本不会设置cookie

Hi the below code sets a Cookies based on a link ID clicked (that's the value), this works but what o need to do it set the domain, i have read how to do this by setting domain in the values, when i set the domin it will not set the cookie at all

工作:

jQuery(document).ready(function(){
    $(".htabs a").click(function(e){
        $.cookie('siteVistedCookie', $(this).attr("id"), { expires: 7, path: '/'});
        });
    });

不起作用

jQuery(document).ready(function(){
    $(".htabs a").click(function(e){
        $.cookie('siteVistedCookie', $(this).attr("id"), { expires: 7, path: '/', domain: 'www.xample.com' });
        });
    });

推荐答案

在这里只是猜测,但是如果您要设置的域不是页面所在的站点的域,则该域(主机)将不能在cookie中设置为您在cookie设置器中输入的域名.

Just guessing here, but if the domain you are trying to set is not the domain of the site the page is hosted on, then the domain (host) will not be set in the cookie to what you type in the as the domain in the cookie setter.

换句话说,如果该域不是托管页面的域,则您正在尝试设置大多数现代浏览器都不允许的第三方cookie.

除非您的站点是xample.com,并且您以xample.com/testcookie.html(或您称为测试页面的任何名称)运行页面,否则cookie的域(主机)将不会设置为xample. com.

Unless your site is xample.com and you are running the page as xample.com/testcookie.html (or whatever you are calling your test page), the domain (host) of the cookie will not be set to xample.com.

这篇关于jQuery $ .cookie(domain :)导致无法设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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