使用jquery在子域上设置cookie [英] Setting cookies on subdomain with jquery

查看:78
本文介绍了使用jquery在子域上设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我网站的域名,例如,mydomain.com有一个子域名en.mydomain.com

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

当用户点击mydomain上的链接时。我需要在en.mydomain.com上设置一个cookie

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

我尝试了以下代码块,但cookie只在当前域mydomain.com上设置而不是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'});

感谢您的帮助!

推荐答案

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

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

这篇关于使用jquery在子域上设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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