1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>5S后返回首页</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> 6 </head> 7 <body> 8 <h2>操作成功</h2> 9 <p><a id="showtime">5s后回到主页</a> <a href="window.history.back()">返回</a></p> 10 11 12 <script type="text/javascript"> 13 14 //通过window的location和history对象来控制网页的跳转。 15 var flag = 5; 16 17 var timer = setInterval(function(){ 18 19 document.getElementById("showtime").innerHTML=flag+"秒后自动跳转到主页"; 20 21 flag=flag-1; 22 23 if(flag<=0){ 24 25 window.location.href=""; 26 27 } 28 29 },1000); 30 31 </script> 32 </body> 33 </html>