ITeye博客

【转】几秒钟跳转页面动态显示时间

wangyanlong0107 · 2012-04-16 12:59 · jsp · Web前端 · Markdown

实现起来很简单,注意

1.在头部加

<meta http-equiv="refresh" content="3;url=../login.jsp">

 

2.在javascript加:

 <script type="text/javascript">
  <!--最初的时间-->
  var time = 4;
  <!--动态时间的显示函数-->
  function returnUrlByTime() {
   <!--每隔1秒调用该函数-->
   window.setTimeout('returnUrlByTime()', 1000);
   <!--时间递减-->
   time = time - 1;
   <!--显示动态时间的层-->
   document.getElementById("layer").innerHTML = time; 
  }
 </script>

 

3.在页面加:

<div id="layer">3</div>秒后跳转到登录页面,如果没有跳转请点击<a href="login.jsp">这里</a>

这是原页面的Code:    

[java] view plaincopy

  1. <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8. <head>
  9. <base href="<%=basePath%>">
  10. <title>错误</title>
  11. <meta http-equiv="refresh" content="3;url=../login.jsp">
  12. <meta http-equiv="pragma" content="no-cache">
  13. <meta http-equiv="cache-control" content="no-cache">
  14. <meta http-equiv="expires" content="0">
  15. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  16. <meta http-equiv="description" content="This is my page">
  17. <!--
  18. <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
  19. -->
  20. <mce:script type="text/javascript">
  21. <!--最初的时间-->
  22. var time = 4;
  23. <!--动态时间的显示函数-->
  24. function returnUrlByTime() {
  25. <!--每隔1秒调用该函数-->
  26. window.setTimeout('returnUrlByTime()', 1000);
  27. <!--时间递减-->
  28. time = time - 1;
  29. <!--显示动态时间的层-->
  30. document.getElementById("layer").innerHTML = time;
  31. }
  32. // --></mce:script>
  33. </head>
  34. <body onload="returnUrlByTime()">
  35. <div>
  36. <center><%=request.getAttribute("message") %></center>
  37. <center><div id="layer">3</div>秒后跳转到登录页面,如果没有跳转请点击<a href="login.jsp" mce_href="login.jsp">这里</a></center>
  38. </div>
  39. </body>
  40. </html>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。