Cookie expiration date

前端 未结 7 1297
梦如初夏
梦如初夏 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:16

    try

    var a = new Date();
    a = new Date(a.getTime() +1000*60*60*24*365);
    document.cookie = 'mycookie=somevalue; expires='+a.toGMTString()+';'; 
    

    PS. The value 1000*60*60*24*365 = 1 Year

    To Get the selected index try this GETcookie:

    function GETcookie(){    
    if (document.cookie){    
    var a = document.cookie;
    Selected = a.substring(a.search('Selected=')+9,a.search(';'));
    alert("Selected = " + Selected);
    document.getElementById('myList').selectedIndex=Selected;
    }}
    

提交回复
热议问题