1. 程式人生 > >倒計時頁面跳轉、jsp 中如何使頁面停留幾秒後再轉向其他頁面

倒計時頁面跳轉、jsp 中如何使頁面停留幾秒後再轉向其他頁面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>請勿重複提交您的資訊!謝謝!</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->


<script type="text/javascript">
var time = 4;



function returnUrlByTime() {


window.setTimeout('returnUrlByTime()', 1000);


time = time - 1;


document.getElementById("layer").innerHTML = time;
}
</script>


</head>


<body  onload="returnUrlByTime()">

<h3>請勿重複提交您的資訊!謝謝!</h3>
<b><span id="layer">3</span>秒後,轉入輸入介面。</b>


<%
//轉向語句
response.setHeader("Refresh", "3;URL=for_input.jsp");
%>


</body>

</html>

==========第二例子===========

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
<head>  
<title>請勿重複提交您的資訊!謝謝!</title>  
</head>
  
<script type="text/javascript">
 function countDown(secs) {
  document.getElementById("jump").innerHTML = secs;
  if (--secs > 0){
   setTimeout("countDown(" + secs + " )", 1000);
   }else{
  <%-- 填寫跳轉地址--%>
   location.href="index.jsp";
   }
 }
 </script>
 
<body style="overflow: auto;" onload="javascript:countDown(5);">


<div align="center">......頁面將在<span id="jump"></span>秒後自動跳轉......
</div>
</body>  
</html>