页面跳转3种方法结合倒计时总结

时间:2021-09-25 00:29:08

一:

<html>
<head>
<script language='javascript' type='text/javascript'>
	var second = 6;
	function djs() {
		if(second<=0){
			window.location.href = "http://www.jd.com";
			return;
		}
		second--;
		var span = document.getElementById('djsSapn');
		span.innerHTML=second.toString();
		setTimeout('djs()', 1000);
	}
</script>
</head>
<body onload="javascript:djs();">
you will go to JD.com in <span id='djsSapn'  style='background:yellow;height:20px;width:30px;'>5</span> seconds
</body>
</html>

二:

<html>
<head>

</head>
<body onload="javascript:djs();">
you will go to JD.com in <span id='djsSapn'  style='background:yellow;height:20px;width:30px;'>5</span> seconds
</body>
<script language='javascript' type='text/javascript'>
	var second = 6;
	//var intervalid = setInterval('djs()',1000);
	
	function djs() {
		if(second<=0){
			window.location.href = "http://www.jd.com";
			return;
		}
		second--;
		var span = document.getElementById('djsSapn');
		span.innerHTML=second.toString();
		setTimeout('djs()', 1000);
	}
</script>
</html>
 

三:Servlet中重定向

 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setStatus(302);
        resp.addHeader("Location", "http://www.baidu.com");
    }

四:servlet中设置响应头

resp.setHeader("refresh", "5,http://www.jd.com");