Arnaud Ad Arnaud Ad - 2 months ago 13
jQuery Question

Setting cookies on subdomain with jquery

The domain of my website which is, let's say, mydomain.com has a subdomain en.mydomain.com

When the user clicks on a link on mydomain.com i need to set a cookie on en.mydomain.com

I tried the following block of code but the cookie is only set on the current domain mydomain.com and not en.mydomain.com

$.cookie("redirectLanguage", "en", { expires: 365,domain: '.mydomain.com'});


thanks for your help!

Answer
//variables
baseDomain = '.domain.com',
expireAfter = new Date();

document.cookie="Name="FName"; domain=" + baseDomain + "; expires=" + expireAfter + "; path=/";