자바 스크립트 방문자수 늘리는 소스점..

<html>
<head>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
<!--
expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+6);
hitCt = eval(cookieVal("pageHit"));
hitCt++;
document.cookie = "pageHit="+hitCt+";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;
}

window.onload = function(){
document.getElementById("pageView").appendChild(document.createTextNode(hitCt));
}
//-->
</SCRIPT>

</head>
<body bgcolor="white">
<div id="pageView"></div>
</body>
</html>

여기에 주석좀 달아주세여..
또 방문자수 늘리는거 이거보다 간단한 소스 없을까요?
좀 어려운듯;;
|

댓글 2개

expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+6); //쿠키 유효기간에 사용할 기간을 6개월간 지속 되도록 정의
hitCt = eval(cookieVal("pageHit")); // cookieVal 함수에 pageHit 라는 값을 넘깁니다. 리턴값으로 쿠키에 저장된 pageHit 값을 가져 옵니다.
hitCt++; //위에서 가져온 값에 +1 합니다.
document.cookie = "pageHit="+hitCt+";expires=" + expireDate.toGMTString(); // 쿠키에 증가한 값을 담고 기한을 6개월간으로 지정합니다.

function cookieVal(cookieName) {
thisCookie = document.cookie.split("; ") //쿠키 값을 분할
for (i=0; i<thisCookie.length; i++) { // 분할된 갯수만큼 루프를 돌려서 pageHit 값을 찾습니다.
if (cookieName == thisCookie[i].split("=")[0]) return thisCookie[i].split("=")[1]; //pageHit를 찾았으면 해당하는 값을 리턴합니다.
}
return 0; //쿠키가 없으면 0을 리턴..
}

window.onload = function(){ //페이지가 로드 되었을때
document.getElementById("pageView").appendChild(document.createTextNode(hitCt)); //pageView ID를 가진 객체에 hitCt 값을 넣습니다.
}
이 소스는 방문하는 사람마다 모두 다르게 나타날 겁니다.
서버에서 집계하는 카운터가 아닌 방문자 스스로가 방문한 횟수를 나타냅니다.
또한 쿠키를 사용하기때문에 브라우저에 쿠키가 지워진다면 정확한 집계가 되질 않습니다.
댓글을 작성하시려면 로그인이 필요합니다.

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
15년 전 조회 1,531
15년 전 조회 1,545
15년 전 조회 1,504
15년 전 조회 5,002
15년 전 조회 2,119
15년 전 조회 1,536
15년 전 조회 1,442
15년 전 조회 1,508
15년 전 조회 4,401
15년 전 조회 3,111
15년 전 조회 1,407
15년 전 조회 1,736
15년 전 조회 1,797
15년 전 조회 2,195
15년 전 조회 1,555
15년 전 조회 1,408
15년 전 조회 1,711
15년 전 조회 3,947
15년 전 조회 1,567
15년 전 조회 1,818