2012. 9. 6. 09:30 COMPUTER/JAVASCRIPT, JQUERY
[JAVASCRIPT] Javascript setCookie getCookie deleteCookie, 자바스크립트 함수

말이 필요없는 함수

 

쿠키 저장

setCookie('변수명','값','만료일','도메인','보안');

 

쿠키 로드

getCookie('변수명');

 

쿠키 삭제

deleteCookie('변수명');

 

 
<script>

function setCookie(cookieName, cookieValue, cookieExpire, cookiePath, cookieDomain, cookieSecure){
	var cookieText=escape(cookieName)+'='+escape(cookieValue);
	cookieText+=(cookieExpire ? '; EXPIRES='+cookieExpire.toGMTString() : '');
	cookieText+=(cookiePath ? '; PATH='+cookiePath : '');
	cookieText+=(cookieDomain ? '; DOMAIN='+cookieDomain : '');
	cookieText+=(cookieSecure ? '; SECURE' : '');
	document.cookie=cookieText;
}

function getCookie(cookieName){
	var cookieValue=null;
	if(document.cookie){
		var array=document.cookie.split((escape(cookieName)+'=')); 
		if(array.length >= 2){
			var arraySub=array[1].split(';');
			cookieValue=unescape(arraySub[0]);
		}
	}
	return cookieValue;
}

function deleteCookie(cookieName){
	var temp=getCookie(cookieName);
	if(temp){
		setCookie(cookieName,temp,(new Date(1)));
	}
}

</script>
 

 

 

 

... ...

댓글을 달아 주세요

최근에 올라온 글

최근에 달린 댓글