[jvs] 자바스크립트로 쿠키 저장 삭제하기 JavaScript_VBScript

<script>
function setCookie(name, value) {
var argc = setCookie.arguments.length
var argv = setCookie.arguments
var expires = (argc > 2) ? argv[2] : null
var path = (argc > 3) ? argv[3] : null
var domain = (argc > 4) ? argv[4] : null
var secure = (argc > 5) ? argv[5] : false
document.cookie = name + "=" + escape(value) +
((expires==null) ? "" : ("; expires=" + expires.toGMTString())) +
((path==null) ? "" : ("; path=" + path)) +
((domain==null) ? "" : ("; domain=" + domain)) +
((secure==true) ? "; secure" : "")
}
function getCookie(name) {
var nameOfCookie = name + "=";
var x = 0

while ( x <= document.cookie.length ) {
var y = (x+nameOfCookie.length);
if ( document.cookie.substring( x, y ) == nameOfCookie ) {
if ( (endOfCookie=document.cookie.indexOf( ";",y )) == -1 )
endOfCookie = document.cookie.length;
return unescape( document.cookie.substring(y, endOfCookie ) );
}
x = document.cookie.indexOf( " ", x ) + 1;
if ( x == 0 )
break;
}
return "";
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = getCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
ttt=prompt();
alert(ttt);
setCookie('a',ttt);
alert(document.cookie);
getCookie('a');
alert(document.cookie);
DeleteCookie('a');
alert(document.cookie);
</script>

덧글

댓글 입력 영역
* 비로그인 덧글의 IP 전체보기를 설정한 이글루입니다.


통계 위젯 (화이트)

2190
4546
10464674

google_myblogSearch_side

▷검색어

Flag Counter style2