页面刷新方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
在js 中添加这些方法后页面会一直刷新,如果想要指定时间刷新一次,可以使用setTimeout() 方法。仍然不是我们想要的进页面后,马上刷新一次。
页面只刷新一次:
function reurl(){ url = location.href; //把当前页面的地址赋给变量 url var times = url.split("?"); //分切变量 url 分隔符号为 "?" console.log(times); if(times[times.length-1] != 1){ //如果?后的值不等于1表示没有刷新 url += "?1"; //把变量 url 的值加入 ?1 setTimeout(function(){ self.location.replace(url); //刷新页面 },2000) } } onload=reurl;
比如:图片过多,一次加载有图片没有显示,过两秒刷新才能显示。
页面首次加载,使用js 获取的元素高度不对。需要刷新后才能获取正确高度。