有 2 种方法可以实现 html 的定时页面跳转,1、meta refresh 实现。2、JavaScript 实现。原文传送门
1、通过 meta refresh 实现 3 秒后自动跳转到 http://www.baidu.com 页面。
- <html>
- <head>
- <meta charset="utf-8">
- <title>前端笔记</title>
- <meta http-equiv="refresh" content="3;url=http://www.baidu.com">
- </head>
- <body>
- </body>
- </html>
2、通过 JavaScript 实现 8 秒后自动跳转到 http://www.cssue.com/ 页面。
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>前端笔记</title>
- <script type="text/javascript">
- var time = 8; //时间,秒
- function Redirect() {
- window.location = "http://www.cssue.com/";
- }
- var i = 0;
- function dis() {
- document.all.s.innerHTML = "还剩" + (time - i) + "秒";
- i++;
- }
- timer = setInterval('dis()', 1000); //显示时间
- timer = setTimeout('Redirect()', time * 1000); //跳转
- </script>
- </head>
- <body>
- <span id="s"></span>
- </body>
- </html>