본문 바로가기
Web Program/Html Lecture

쿠키 설정 및 쿠키 검사

by 현이빈이 2008. 9. 4.
반응형
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 setCookie(name, value, expiredays){
 var todayDate = new Date();
 todayDate.setDate(todayDate.getDate() + expiredays);
 document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

반응형