下面是一个在用户电脑上写了12个月的 JavaScript cookie。
在主域(如 example.com)上设置 cookie 之后,如果用户访问子域(如 test.example.com) ,我们需要继续识别用户在“测试”子域上的活动。
But with the current code, as soon as they leave www.example.com and visit test.example.com, they are no longer flagged as "HelloWorld".
是否有人能够帮助我的代码,以便允许在子域之间读取 cookie?
<script type="text/javascript">
var cookieName = 'HelloWorld';
var cookieValue = 'HelloWorld';
var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 12);
document.cookie = cookieName +"=" + cookieValue + ";expires=" + myDate;
</script>