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
Working:
jQuery(document).ready(function(){
$(".htabs a").click(function(e){
$.cookie('siteVistedCookie', $(this).attr("id"), { expires: 7, path: '/'});
});
});
Not working
jQuery(document).ready(function(){
$(".htabs a").click(function(e){
$.cookie('siteVistedCookie', $(this).attr("id"), { expires: 7, path: '/', domain: 'www.xample.com' });
});
});
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.
In other words, if the domain is not the domain of the hosted page, you are trying to set a third-party cookie which most modern browsers do not allow.
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.
Run the script without the domain setting, then look at the cookie it sets. What domain does it show? Does it match up with what you are putting into the domain property?
Cookie domains must be set with the same (sub) domain the page is on. For instance, if your page is on
http://www.somesite.com/page.htm
l
You can set your cookie domain as
www.somesite.com
<-- this will specifically set it for www
subdomain
.somesite.com
<-- this will allow it to be set for any subdomain of somesite.com
精彩评论