I am trying to re-direct user to a specific page based on condition. If Timer still running open booknow.html if timer expired open booknowcode.html
Pseudo code
- Timer still running
- User clicks Book Now button
If condition :
a) if timer still running -> send user to booknowcode.html page
b) if timer expired -> send user to booknow.html page
// Set the date we're counting down to
var countDownDate = new Date("June 30, 2021 09:17:25").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="timer"
document.getElementById("timer").innerHTML = days + "d " + hours + "h " +
minutes + "m " + seconds + "s " + "Discount 15%";
// If the count down is over, write Expired text
if (distance < 0) {
clearInterval(x);
document.getElementById("timer").innerHTML = "EXPIRED";
}
//===if timer still running then redirect to dicount page (distance more than zero) Start ===
let link;
if (distance <= 0) {
link = "booknow.html";
} else {
link = "booknowcode.html";
}
document.getElementById("demo").innerHTML = link;
//===if timer still running then redirect to dicount page (distance more than zero) End ===
}, 1000);
<div class="timer-button" id="conditional-button">
<p id="timer"></p>
<a href="booknow.html">
<button class="btn btn-info" type="button" onclick="">Book Now</button>
</a>
</div>
<p id="demo"></p>
So how do I replace booknow.html with booknowcode.html based on the timer condition?