Reputation: 1047
Is it possible to redirect to another URL for certain time, for example from 06:00 to 08:00, and for the rest of the day some other URL.
Upvotes: 0
Views: 674
Reputation: 12127
HTML / JavaScript does not provide such type facility to redirect page in between time but you can apply trick using JavaScript, see sample code
var hours = new Date().getHours();
if(hours >= 6 && hours <= 8){
window.location.href = "some_url";
}else{
window.location.href = "some_other_url";
}
Upvotes: 2
Reputation: 21666
Yes, you can use Date object and get the time and then match it against your desired time and put it in if
block with above condition, and use something from below
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
or
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
Also see: Javascript redirect based on date
Upvotes: 1