请听我说完。假设一个页面必须在每个工作日上午9:30重新加载。该页面在上午9点打开。因此,在上午9:15,该页面应该自动重新加载,而无需任何用户干预。可以做些什么。非常感谢您的帮助
function checkTime() {
var d = new Date(); // current time
var hours = d.getHours();
var mins = d.getMinutes();
if (hours >= 17 || hours <= 18) {
setInterval(() => {
location.reload();
}, 5000);
}
}
我想你已经根据这篇文章提出了这个问题。
但为了快速帮助您,我已经复制了代码。
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((函数
refreshAt(15,35,0); //Will refresh the page at 3:35pm
信用额度:https://stackoverflow.com/users/26210/andrew-moore