HTML 定时页面跳转

有 2 种方法可以实现 html 的定时页面跳转,1、meta refresh 实现。2、JavaScript 实现。原文传送门

1、通过 meta refresh 实现 3 秒后自动跳转到 http://www.baidu.com 页面。

[html]  view plain  copy
  1. <html>  
  2. <head>  
  3. <meta charset="utf-8">  
  4. <title>前端笔记</title>  
  5. <meta http-equiv="refresh" content="3;url=http://www.baidu.com">  
  6. </head>  
  7. <body>  
  8. </body>  
  9. </html>  

2、通过 JavaScript 实现 8 秒后自动跳转到 http://www.cssue.com/ 页面。

[html]  view plain  copy
  1. <!doctype html>  
  2. <html>  
  3. <head>  
  4. <meta charset="utf-8">  
  5. <title>前端笔记</title>  
  6. <script type="text/javascript">  
  7. var time = 8; //时间,秒  
  8. function Redirect() {  
  9.     window.location = "http://www.cssue.com/";  
  10. }  
  11. var i = 0;  
  12. function dis() {  
  13.     document.all.s.innerHTML = "还剩" + (time - i) + "秒";  
  14.     i++;  
  15. }  
  16. timer = setInterval('dis()', 1000); //显示时间  
  17. timer = setTimeout('Redirect()', time * 1000); //跳转  
  18. </script>  
  19. </head>  
  20. <body>  
  21. <span id="s"></span>  
  22. </body>  
  23. </html> 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值