I have a countdown timer in javascript which finally works after some tinkering, but one problem still persists. I have it set to reload the index.php page when the counter gets to zero, which it does, but for some reason it does not load any of my included php files like my CSS or PDO connection files.
include(“include/connect.php”);
include(“include/define.php”);
include(“header.php”);
This is a stupid work-around, but if I have the javascript redirect to test.php and then test.php redirects back to index.php it works, but I’d rather have this working properly. The javascript is below. I have tried various ways of redirecting but the same thing happens.
Thanks (I hope this is OK in the PHP group)
if(localStorage.getItem("count_timer")){
var count_timer = localStorage.getItem("count_timer");
} else {
var count_timer = 60;
}
var minutes = parseInt(count_timer/60);
var seconds = parseInt(count_timer%60);
function countDownTimer(){
if(seconds < 10){
seconds= "0"+ seconds ;
}if(minutes < 10){
minutes= "0"+ minutes ;
}
function Redirect() {
window.location = "test.php";
}
document.getElementById("total-time-left").innerHTML = minutes+":"+seconds;
if(count_timer <= 0){
localStorage.clear("count_timer");
setTimeout(function() {
Redirect();
}, 100);
} else {
count_timer = count_timer -1 ;
minutes = parseInt(count_timer/60);
seconds = parseInt(count_timer%60);
localStorage.setItem("count_timer",count_timer);
setTimeout("countDownTimer()",1000);
}
}
setTimeout("countDownTimer()",1000);