기본

쿠키를 이용한 방문 횟수 카운터 스크립트

by 보석 posted Sep 04, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄
Extra Form
미리보기 http://linfree.com/javaboard/5.html


<style>
.counter{ /*카운터 상자의 모양을 설정합니다*/
        background-color:black; /*배경색*/
        color:yellow;/*글자색상*/
        font-weight:bold;/*글자모양*/
}
</style>

<script>
<!--
expireDate = new Date; // 새로운 날짜객체생성
expireDate.setMonth(expireDate.getMonth()+6) //쿠키를 6개월간 유지
jcount = eval(cookieVal("jasko"))
jcount++
document.cookie = "jasko="+jcount+";expires=" + expireDate.toGMTString()

function cookieVal(cookieName) {
        thisCookie = document.cookie.split("; ")
        for (i=0; i<thisCookie.length; i++){
                        if (cookieName == thisCookie[i].split("=")[0]){
                                        return thisCookie[i].split("=")[1]
                        }
        }
        return 0
}

function page_counter(){
        for (i=0;i<(7-jcount.toString().length);i++)
        document.write('<span class="counter">0</span>')
        for (y=0;y<(jcount.toString().length);y++)
        document.write('<span class="counter">'+jcount.toString().charAt(y)+'</span>')
}
//-->
</script>

<!--아래의 방식으로 스크립트나 HTML 태그를 붙여 넣으세요-->

손님은 린프리에 <script>page_counter(jcount);</script> 번째로 방문 하셨네요.<!---->