기본

현재시간 로그인한시간 홈페이지 머문시간을 알려주는 스크립트

by 보석 posted Sep 07, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

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


<!----- 1. 아래의 스크립트를 HEAD 부분에 붙여 넣으세요 -------->

<SCRIPT LANGUAGE="JavaScript">
<!--
var onHours = " ";
var onMinutes = " ";
var onSeconds = " ";
var offHours = 0;
var offMinutes = 0;
var offSeconds = 0;
var logSeconds = 0;
var logMinutes = 0;
var logHours = 0;
var OnTimeValue = " ";
var OffTimeValue = " ";
var PageTimeValue = " ";

function getLogonTime() {
var now = new Date();
var ampm = (now.getHours() >= 12) ? " P.M." : " A.M."
var Hours = now.getHours();
Hours = ((Hours > 12) ? Hours - 12 : Hours);
var Minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
var Seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
OnTimeValue =(" "
+ Hours
+ Minutes
+ Seconds
+ " "
+ ampm);
onHours = now.getHours();
onMinutes = now.getMinutes();
onSeconds = now.getSeconds();
}
function getLogoffTime() {
var now = new Date();
var ampm = (now.getHours() >= 12) ? " P.M." : " A.M."
var Hours = now.getHours();
Hours = ((Hours > 12) ? Hours - 12 : Hours);
var Minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
var Seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
OffTimeValue =(" "
+ Hours
+ Minutes
+ Seconds
+ " "
+ ampm);
offHours = now.getHours();
offMinutes = now.getMinutes();
offSeconds = now.getSeconds();
timer();
}
function timer() {
if (offSeconds >= onSeconds) {
logSeconds = offSeconds - onSeconds; }
else {
offMinutes -= 1;
logSeconds = (offSeconds + 60) - onSeconds;
}
if (offMinutes >= onMinutes) {
logMinutes = offMinutes - onMinutes; }
else {
offHours -= 1;
logMinutes = (offMinutes + 60) - onMinutes;
}
logHours = offHours - onHours;
logHours =  ((logHours < 10) ? "0" : ":") + logHours;
logMinutes = ((logMinutes < 10) ? ":0" : ":") + logMinutes;
logSeconds = ((logSeconds < 10) ? ":0" : ":") +logSeconds;
PageTimeValue =(" "
+ logHours
+ logMinutes
+ logSeconds);
displayTimes();
}
function displayTimes() {
alert("\n로그인한 시간 : " +OnTimeValue+"\n\n현재 시간 : "+OffTimeValue+"\n\n머무른 시간 : " + PageTimeValue);
}
// -->
</SCRIPT>

<!------------------ 여기까지 --------------->

</HEAD>

<!----- 2. BODY 태그안에 아래의 이벤트 핸들러를 붙여 넣으세요 -->

<BODY onLoad="getLogonTime()">

<!----- 3. 원하는 위치에 아래와 같이 코드를 붙여 넣으세요 ------->

<CENTER>
<FORM>
<INPUT TYPE="button" value="페이지에 머문 시간 보기" onClick="getLogoffTime()">
</FORM>
</CENTER>

<!------------------ 여기까지 -------------->



미리보기 참조