让网页在打开几秒之后就转向其它的页面
author:一佰互联 2019-04-20   click:180
只要加入以下的代码就可以实现。
第一种方法:使用Meta
用法: <Meta http-equiv=Refresh Content=30>
<Meta http-equiv="Refresh" Content="5; Url=http://sc.jb51.net">
其中第一条语句是停留30秒自动刷新,第二条是停留5秒转向sc.jb51.net。分别使用可实现自动刷新或自动转向功能。

第二种:js实现
setTimeout(function(){window.location.href = "http://sc.jb51.net";},2000)
第三种带倒计时的js代码
复制代码代码如下:
<html>
<head>
<title>10秒后跳转</title>
</head>
<body>
<input type="text" readonly="true" value="10" id="time">
</body>
<script language="javascript">
var t = 10;
var time = document.getElementById("time");
function fun(){
t--;
time.value = t;
if(t<=0){
location.href = "https://www.yinxi.net";
clearInterval(inter);
}
}
var inter = setInterval("fun()",1000);
</script>
</html>

页面跳转功能当然也可以用js来实现,不过上面的代码的优点就是浏览不支持js的情况下,也可以使用。如果实现实时的倒计时效果,就需要用js来实现了,一般情况下,可以两者结合判断下。
javascript 页面跳转方法集合
用meta实现的页面跳转代码