例:
setInterval(function(){
window.location.reload()
},5000)
这样是每隔五秒刷新一次当前页面
<script>setInterval(function(){
var d=new date()
if(d.getFullYear()==2018&&d.getMonth()==0&&d.getDate()==27&&d.getHours()==18&&d.getMinutes()==0)
location.reload()
},60000)
</script>
以上代码只会在指定时间(2018-1-27 18:00:00)刷新一次,如果希望每天的同一时间(比如18点整)都刷新,则
<script>setInterval(function(){
var d=new date()
if(d.getHours()==18&&d.getMinutes()==0)
location.reload()
},60000)
</script>
如果只是纯按照一定时间间隔刷新 最方便的使用这个<meta http-equiv="refresh" content="刷新间隔的秒数url=网址">
如果你是想再某个事件被触发的情况下 刷新就用这个
location.reload()
或者
history.go(0)
刷新本页其实就是重定向到本页
所以也可以
location.href="网址"
如果你想用js代码让页面自动刷新可以用定时执行的函数来实现
假设定时刷新的时间间隔是10秒 即 10000毫秒
手写代码:
<script>
function refresh()
{
location.reload()
}
setTimeout("refresh()",10000) //一旦计时到了10000毫秒就执行 refresh()函数
</script>