我有一个网站,我想在一定时间重新加载,如下午3:35,不是在一个特定的间隔,如5分钟.我怎么做?
解决方法
以下
JavaScript代码段将允许您在给定时间刷新:
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