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>

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。