F
fb
Hello everyone. I have a javascript timer counting down inside a web
page (technically a .php page). We have the page load items from a
database and refresh, but this resets our counter. So, I was wondering
if there is a way to keep the timer counting down, even though we
refresh the page (or move to a different page...we are still up in the
air on which is easier/better). I'm not usually a web developer kinda
person, I usually stick to writing general applications in C, C++ or
Java, so let me know if you need more info. The timer code follows:
<script type="text/javascript">
function display_c(start){
window.start = parseFloat(start);
var end = 0 // change this to stop the counter at a higher value
var refresh=1000; // Refresh rate in milli seconds
if(window.start >= end ){
mytime=setTimeout('display_ct()',refresh)
}
else {
alert("Time Over ");
}
}
function display_ct() {
// Calculate the number of days left
var days=Math.floor(window.start / 86400);
// After deducting the days calculate the number of hours left
var hours = Math.floor((window.start - (days * 86400 ))/3600)
// After days and hours , how many minutes are left
var minutes = Math.floor((window.start - (days * 86400 ) - (hours
*3600 ))/60)
// Finally how many seconds left after removing days, hours and minutes.
var secs = Math.floor((window.start - (days * 86400 ) - (hours *3600
) - (minutes*60)))
var x = " " + "Time left : " + minutes + " Minutes and " + secs +
" Seconds " + " ";
document.getElementById('ct').innerHTML = x;
window.start= window.start- 1;
tt=display_c(window.start);
}
</script>
<body onload=display_c(1800);>
<span id='ct' style= "background-color: black"></span>
</body>
fb
page (technically a .php page). We have the page load items from a
database and refresh, but this resets our counter. So, I was wondering
if there is a way to keep the timer counting down, even though we
refresh the page (or move to a different page...we are still up in the
air on which is easier/better). I'm not usually a web developer kinda
person, I usually stick to writing general applications in C, C++ or
Java, so let me know if you need more info. The timer code follows:
<script type="text/javascript">
function display_c(start){
window.start = parseFloat(start);
var end = 0 // change this to stop the counter at a higher value
var refresh=1000; // Refresh rate in milli seconds
if(window.start >= end ){
mytime=setTimeout('display_ct()',refresh)
}
else {
alert("Time Over ");
}
}
function display_ct() {
// Calculate the number of days left
var days=Math.floor(window.start / 86400);
// After deducting the days calculate the number of hours left
var hours = Math.floor((window.start - (days * 86400 ))/3600)
// After days and hours , how many minutes are left
var minutes = Math.floor((window.start - (days * 86400 ) - (hours
*3600 ))/60)
// Finally how many seconds left after removing days, hours and minutes.
var secs = Math.floor((window.start - (days * 86400 ) - (hours *3600
) - (minutes*60)))
var x = " " + "Time left : " + minutes + " Minutes and " + secs +
" Seconds " + " ";
document.getElementById('ct').innerHTML = x;
window.start= window.start- 1;
tt=display_c(window.start);
}
</script>
<body onload=display_c(1800);>
<span id='ct' style= "background-color: black"></span>
</body>
fb