-
detect and redirect based on time
I have an index.html. This page redirects based on time of day. I would like it to redirect as follows
6am-9am=morning.html
9am-8pm=day.html
8pm-6am=night.html
the night and the day function fine but when it is time for the morning to redirect it defaults to the day.html. Have i done something wrong in this code. Any help would be greatly appreciated.function ampmRedirect(dayURL, nightURL) {
var currentTime = new Date();
var currentHour = currentTime.getHours();if ((currentHour < 6) || (currentHour > 20)) {
window.location.href = “night.html”;
} else if (currentHour >=9 || currentHour <17) {
window.location.href = "day.html";
} else {
window.location.href = "morning.html";
}
}
// -->BODY onLoad=”ampmRedirect(‘morning.html’,’day.html’,’eve.html’,’night.html’)””>
Thanks Rik
Sorry, there were no replies found.