I made like this:
Code: Select all
echo '<h4><center>' . $lang['Building'][$language] . "</h4>";
$currentTime = time();
$futureTime = $aldeia_info['tempoc'];
echo '<h4 id="timer"></h4>';
<script type="text/javascript">
var currentTime = <?php echo time(); ?>,
futureTime = <?php echo $tempoc; ?>,
timer = document.getElementById('timer');
function timeLeft(current, end)
{
var days = 0,
hours = 0,
minutes = 0,
seconds = 0,
left = end - current;
if( left > 0 )
{
days = Math.floor(left / 86400);
left -= days*86400;
hours = Math.floor(left / 3600);
left -= hours*3600;
minutes = Math.floor(left/60);
seconds = left - minutes * 60;
}
else
{
window.location.reload();
}
//return days + ':' + hours + ':' + minutes + ':' + seconds;
//return minutes + ':' + seconds;
return ( days > 0 ? days + 'd:' : '' ) + ( hours > 0 ? hours + 'h:' : '' ) + minutes + 'min:' + seconds + 's';
}
setInterval( function()
{
currentTime++;
timer.innerHTML = timeLeft(currentTime, futureTime);
}, 1000 ); // loop every second
</script>
It was working until now that when it reaches 0, it reloads forever..
I know the error is in
Code: Select all
window.location.reload();