网页定时自动跳转 这个功能看起来不起眼,确实我们在日常生活工作当中经常需要用到的功能,比如,支付成功后自动跳转、下单成功后自动跳转、出现404错误页面后自动跳转、网址发布页定时跳转等等;
网页定时自动跳转 这个功能看起来不起眼,确实我们在日常生活工作当中经常需要用到的功能,比如,支付成功后自动跳转、下单成功后自动跳转、出现404错误页面后自动跳转、网址发布页定时跳转、旧域名网址跳转至新域名等等;
要实现页面跳转的这个功能没有什么太大的技术难度,下面笔者就将常用的方法收集整理,以便自己在需要的时候可以随时查阅,当然也可以让有需要的网友可以借鉴参考!

使用setTimeout函数实现 网页定时自动跳转
如下代码要写在body区域内
<script type="text/javascript">
//3秒钟之后跳转到指定的页面
setTimeout(window.location.href='https://bitchina.info',3);
</script>
或者
<script language="JavaScript" type="text/javascript">
function Redirect(){
window.location = "https://bitchina.info"; //要跳转的页面
}
setTimeout('Redirect()', 3000); //第二个参数是时间,单位毫秒
</script>
使用meta信息实现 网页定时自动跳转
在页面的head区域块内加上如下代码
<!--5秒钟后跳转到指定的页面-->
<meta http-equiv="refresh" content="5;url=https://bitchina.info" />
使用脚本语言实现 网页定时自动跳转
就一句最简单
<%response.setHeader("Refresh","3;url=https://bitchina.info");%>
带数字倒计时功能的 网页定时自动跳转
方法一
<!doctype html>
<head>
<meta charset=utf-8" />
<title>js定时跳转页面的方法</title>
</head>
<body>
<script>
var t=10;//设定跳转的时间
setInterval("refer()",1000); //启动1秒定时
function refer(){
if(t==0){
location="https://bitchina.info"; //#设定跳转的链接地址
}
document.getElementById('show').innerHTML=""+t+"秒后跳转到比特中国"; // 显示倒计时
t--; // 计数器递减
//本文转自:
}
</script>
<span id="show"></span>
</body>
</html>
方法二
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- 完成页面定时的跳转 -->
<meta http-equiv="refresh" content="5;url=https://bitchina.info">
<title>Insert title here</title>
</head>
<body onload="run()">
页面将在<span id="spanId">5</span>秒后跳转!!
</body>
<br>
<script type="text/javascript">
// 页面一加载完成,该方法就会执行
// 读秒,一秒钟数字改变一次
var x = 5;
function run(){
// 获取到的是span标签的对象
var span = document.getElementById("spanId");
// 获取span标签中间的文本
span.innerHTML = x;
x--;
// 再让run方法执行呢,一秒钟执行一次
window.setTimeout("run()", 1000);
}
</script>
</html>
方法三
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<script type="text/javascript">
function countDown(secs,surl){
var jumpTo = document.getElementById('jumpTo');
jumpTo.innerHTML=secs;
if(--secs>0){
setTimeout("countDown("+secs+",'"+surl+"')",1000);
}
else{
location.href=surl;
-ma
}
}
</script>
</head><br>
<body>
<h1>提交成功</h1>
<a href="https://bitchina.info"><span id="jumpTo">3</span>秒后系统会自动跳转,也可点击本处直接跳</a>
<script type="text/javascript">
countDown(3,'https://bitchina.info');
</script>
</body>
</html>
参考原文:https://www.cnblogs.com/javahr/p/8410371.html
原创文章,作者:黑帽阿九,如若转载,请注明出处:https://bitchina.info/wangyedingshizidongtiaozhuan-deshixianfangfadaimadaquanjianyishoucang/.html