我想让我的wordpress主页在每天的特定时间刷新,即晚上8:59我对CSS和HTML略知一二,但对Javascript几乎一无所知,所以如果你能详细解释解决方案,那将是非常有帮助的。
具体的用例是,我嵌入了一个预定的Facebook live流,如果用户在流上线之前已经加载了站点,则需要刷新。我们的节目晚上9点开始,流在8:59开始直播,所以如果我们能在8:59强制自动刷新,我们就可以确保没有人错过流(我们的观众大多是不太精通技术的老年人)。
提前感谢!
发布于 2019-02-24 07:15:31
setInterval(function(){
const date = new Date();
const hour = date.getHours();
const minute = date.getMinutes();
console.log(hour, minute);
if(hour == 8 && minute == 59){
location.reload();
}
},1000);根据本地时间返回指定日期内的小时。如果需要协调世界时,请使用新日期(Date.UTC(...))使用相同的参数。
发布于 2019-02-24 07:16:52
function refreshAt(hours, minutes, seconds)
{
var now = new Date();
var then = new Date();
if ( now.getHours() > hours || (now.getHours() == hours &&
now.getMinutes() > minutes) || now.getHours() == hours &&
now.getMinutes() == minutes && now.getSeconds() >= seconds )
{
then.setDate(now.getDate() + 1);
}
then.setHours(hours);
then.setMinutes(minutes);
then.setSeconds(seconds);
var timeout = (then.getTime() - now.getTime());
setTimeout(function() { window.location.reload(true); }, timeout);
}要运行此函数,请使用
refreshAt(18,45,0); //Will refresh the page at 18:45pmhttps://stackoverflow.com/questions/54847193
复制相似问题