有 2 種方法可以實現 html 的定時頁面跳轉,1、meta refresh 實現。2、JavaScript 實現。
1、通過 meta refresh 實現 3 秒后自動跳轉到 http://www.cnblogs.com/wuxibolgs329/ 頁面。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>前端筆記</title>
<meta http-equiv="refresh" content="3;url=http://www.cnblogs.com/wuxibolgs329/">
</head>
<body>
</body>
</html>
2、通過 JavaScript 實現 8 秒后自動跳轉到 http://www.cnblogs.com/wuxibolgs329/ 頁面。
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <span id="s"></span> <script type="text/javascript"> var s = document.getElementById('s'); var time = 8; //時間,秒 function Redirect() { window.location = "http://www.baidu.com/"; } var i = 0; function dis() { s.innerHTML = "還剩" + (time - i) + "秒"; i++; } timer = setInterval('dis()', 1000); //顯示時間 timer = setTimeout('Redirect()', time * 1000); //跳轉 </script> </body> </html>
