简体   繁体   English

设置Cookie过期日期-Javascript

[英]Set cookie expire date - Javascript

I was trying to create a cookie with a defined expiration date. 我试图创建一个具有定义的到期日期的cookie。 Here's my code: 这是我的代码:

function setCookie(){
  var date=new Date();
  date.setFullYear(2015);
  document.cookie="cookie_name=tracking_true; expires=" +date.toUTCString() + ";";
}

When I check into my browser (from Google Chrome console I type: document.cookie), I can find only this: cookie_name=tracking_true. 当我登录浏览器(从Google Chrome控制台输入:document.cookie)时,只能找到以下内容:cookie_name = tracking_true。 I cannot find the expires date. 我找不到过期日期。 Do you have any idea why I cannot see the exiperes date? 您知道为什么我看不到药方日期吗?

Thanks, Alessio 谢谢,Alessio

document.cookie displays only the cookie names. document.cookie仅显示cookie名称。 To see other parameters, in Chrome, use developer tools, resources tab, then cookies. 要查看其他参数,请在Chrome中使用开发者工具,资源标签,然后使用Cookie。 In Firebug, use the cookies tab. 在Firebug中,使用Cookies标签。 There is documentation here: https://developer.mozilla.org/en-US/docs/Web/API/document.cookie 这里有文档: https : //developer.mozilla.org/en-US/docs/Web/API/document.cookie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM