JSP 페이지를 개발했습니다. 이 페이지에는 시간을 표시하는 카운트 다운 타이머가 hh:mm:ss
있습니다. 이 페이지에서 이전 페이지 (2 페이지)에 링크가 제공됩니다. 2 페이지의 일부 작업이 끝나면 컨트롤이 1 페이지로 다시 전송됩니다.사용자가 페이지를 떠날 때부터 타이머를 다시 시작
페이지 1이로드 될 때 시작되는 타이머가 있습니다. 2 페이지로 이동하여 1 페이지로 돌아 가면 타이머가 새로 고쳐집니다. 페이지를 떠날 때부터 어떻게 시작 할 수 있습니까? 난 당신이 2 페이지로 전환하기 전에 진정한 = 현재 시간과 하나 개의 플래그를 저장하기 위해 쿠키를 사용 할 수 있다고 생각
<script language="JavaScript">
function countdown(elementName, minutes, seconds)
{
var element, endTime, hours, mins, msLeft, time;
function twoDigits(n) {
return (n <= 9 ? "0" + n : n);
}
function getCurrentTime() {
time = new Date();
hours = time.getUTCHours();
mins = time.getUTCMinutes();
secs = time.getUTCSeconds();
alert(hours + " " + mins + " " + secs);
}
function updateTimer() {
msLeft = endTime - (+new Date);
if (msLeft < 999) {
alert("please save your work and send your file!");
} else {
time = new Date(msLeft);
hours = time.getUTCHours();
mins = time.getUTCMinutes();
secs = time.getUTCSeconds();
element.innerHTML = (hours ? hours + ':' + twoDigits(mins) : mins) + ':' + twoDigits(secs);
setTimeout(updateTimer, time.getUTCMilliseconds() + 500);
}
if(hours == 0 && mins == 0 && secs == 59) alert("dsdsdsdsdsd");
}
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}
function getCookie (name) {
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}
var exp = new Date();
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30));
element = document.getElementById(elementName);
endTime = (+new Date) + 1000 * (60*minutes + seconds) + 500;
updateTimer();
}
</script>
확인 예제 전체 코드입니다
이의를 – Rohhit
를 시간 문자열을 구문 분석 난에 값을 설정 당신이 말한대로 쿠키하지만 나는 다시 1 페이지로 돌아갈 때 쿠키 값을 설정할 수 없습니다. pls 샘플 코드 또는 링크를 게시 할 수 있습니다 나를 도울 수 .... ?? – Rohhit
코드를 게시하기 만하면 문제가 해결되지 않으면 코드를 시도해보고 주석/문제를 작성하십시오. –