Hello...
I use javascript countdown timer in my page.
Each time the page is being refreshed, the countdown is restarting.
I blocked the F5 function to avoid the page being refreshed.
It works, but it doesnt block the browser's refresh button.

So what i gonna do is unblocked the F5, since it doesnt do any good.
Then i need to store the time into cookies, exactly when the page is refreshed.
The cookie is used to process the time then continue the countdown timer.

Below are my scripts:

<html>
<head>
<title>Timer Test</title>


<script type="text/javascript">
var _countDowncontainer=0;
var _currentSeconds=0;


function ActivateCountDown(strContainerID, initialValue) {
_countDowncontainer = document.getElementById(strContainerID);


if (!_countDowncontainer) {
alert("count down error: container does not exist: "+strContainerID+
"\nmake sure html element with this ID exists");
return;
}


SetCountdownText(initialValue);
window.setTimeout("CountDownTick()", 1000);
}


function CountDownTick() {
if (_currentSeconds <= 0) {
alert("your time has expired!");
return;
}


SetCountdownText(_currentSeconds-1);
window.setTimeout("CountDownTick()", 1000);
}


function SetCountdownText(seconds) {
//store:
_currentSeconds = seconds;


//get minutes:
var minutes=parseInt(seconds/60);


//shrink:
seconds = (seconds%60);


//get hours:
var hours=parseInt(minutes/60);


//shrink:
minutes = (minutes%60);


//build text:
var strText = AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds);


//apply:
_countDowncontainer.innerHTML = strText;
}


function AddZero(num) {
return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}
</script>
<script type="text/javascript">
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 100);
document.dodi.tombol.disabled="disabled"
}


document.onkeydown=checkKeyCode;


</script>


</head>
<body>
Time remaining: <span id="CountDownPanel"></span></br>
<form name=dodi>
<td><input type="button" name="tombol" value="Start"  onClick="WindowLoad()"></td></tr>
</form>


</body>
</html>

After i pressed the start button, the countdown starts.
Is there a way to save the value of countdown timer into cookie when the page is refreshed?
Many thanks for the help....

Why do this? It seems pointless.

Why do this? It seems pointless.

Well the countdown has the set timeout. When the page is refreshed, the set timeout always start from beginning. i need to get the time when the page is refreshed, so i can have the elapsed time.

Then the new set timeout = the previous set timeout - elapsed time.

But actually, i found some way to do this using session instead of cookies. Though it needs some modification on the javascript.

Thanks anyway...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.