get/set cookies

1133 단어
cookies 쓰기 대상
function setcookie(name,value,daysToLive){
      var cookie = name + "=" encodeURIComponent(value);
      if(typeof daysToLive === "number"){
         cookie += "; max-age=" + (daysToLive*60*60*24);//max-age  cookie 
   }
      document.cookie = cookie;

}
 , cookie path、domain、secure , cookie , cookie :
;path = path                //   cookie 
;domain = domain       // cookie 
;secure                        // , cookie ,cookie 

문서 분석.쿠키 속성 값
function getcookie(){
      var cookie = {};// 
      var all = document.cookie;// cookie 
      if(all === ""){// cookie 
            return cookie;// 
      }
      var list = all.split("; ");// / 
      for(var i = 0; i < list.length; i++){// cookie
            var cookie = list[i];
            var p = cookie.indexOf("=");// “=” 
            var name = cookie.substring(0,p);// cookie 
            var value = cookie.substring(p+1);// cookie 
            value = decodeURIComponent(value);// 
            cookie[name] = value;// / 
      }
      return cookie;
}

좋은 웹페이지 즐겨찾기