html 页面自动刷新代码 :实现html页面自动刷新的几种方法
1、通过在head标签中添加meta标签来实现
<!--页面每1秒刷新一次-->
<meta http-equiv="Refresh" content="1";/>
<!--5秒钟后页面自动跳转到指定页面-->
<meta http-equiv="Refresh" content="5;url=http://www.w3school.com.cn" />
2、通过js来实现页面刷新或者跳转
<script>
function Refresh() {
window.location.reload();
}
setTimeout('Refresh()',1000); //1秒刷新一次
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function goUrl(){
var url="http://www.baidu.com";
location.href=url;
}
</script>
</head>
<!--1秒钟后页面自动跳转到百度-->
<body onload="setTimeout('goUrl()', 1000);">
</body>
</html>
<html>
<head>
<script>
var t=10;
setInterval("refer()",1000);
function refer(){
if(t==0){
location.href="//www.baidu.com";
}
// 倒计时提示跳转
document.getElementById('show').innerHTML=""+t+"秒后跳转到百度";
t--;
}
</script>
</head>
<body>
<span id="show"></span>
</body>
</head>
</html>