javascript set cookie with expire time

后端 未结 8 609
日久生厌
日久生厌 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:33

    Use like this (source):

    function setCookie(c_name,value,exdays)
    {
    
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie = c_name+"="+c_value+"; path=/";
    }
    
    0 讨论(0)
  • 2020-11-27 14:37

    Your browser may be configured to accept only session cookies; if this is your case, any expiry time is transformed into session by your browser, you can change this setting of your browser or try another browser without such a configuration

    0 讨论(0)
提交回复
热议问题