javascript set cookie with expire time

后端 未结 8 730
日久生厌
日久生厌 2020-11-27 14:03

I am setting a cookie by Javascript and it is working fine but it is not taking the expire time I am giving. It keeps on taking session value regardless of what I give, belo

8条回答
  •  眼角桃花
    2020-11-27 14:31

    I think its ok. I've set time to 1000*36000. toGMTString is deprecated please use toUTCString instead.

    function display() { 
      var now = new Date();
      var time = now.getTime();
      var expireTime = time + 1000*36000;
      now.setTime(expireTime);
      var tempExp = 'Wed, 31 Oct 2012 08:50:17 GMT';
      // document.cookie = 'cookie=ok;expires='+now.toUTCString()+';path=/';
      document.cookie = 'cookie=ok;expires='+now.toGMTString()+';path=/';
      //console.log(document.cookie);
    }
    

    expiration

提交回复
热议问题