Cookie expiration date

前端 未结 7 1157
梦如初夏
梦如初夏 2020-12-30 01:43

I am not a programmer. I am trying to use a cookie script that remembers the last drop down menu selection.

I found a script that works but it does only a session co

相关标签:
7条回答
  • 2020-12-30 02:26

    Try this:

    function setCookie(c_name,c_value,exdays) {
       var exdate=new Date();
       exdate.setDate(exdate.getDate() + exdays);
       document.cookie=encodeURIComponent(c_name) 
         + "=" + encodeURIComponent(c_value)
         + (!exdays ? "" : "; expires="+exdate.toUTCString());
         ;
    }
    

    c_name is the name of the cookie

    c_value is the cookie value

    exdays is the number of days you want the cookie to expire after

    Source: http://www.w3schools.com/js/js_cookies.asp

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