html网页跳转javascript代码实现

假设a.html和b.html在同一个文件夹下面,请在a.html页面中使用javascript代码实现:在浏览器中打开a.html五秒钟后,自动跳转到b.html页面.

代码如下:

<html>
 <head>
  <title> page A </title>
  <script type="text/javascript">
function delyLoad(){
setTimeout(function(){
 window.location.href='b.html';
},5000)
}
  </script>
 </head>

 <body onload="delyLoad()">
<h1>A</h1>
 </body>
</html>

首先做一个计时器,记时5秒。5秒后将location的链接转为b.html。如果b.html与a不在同一个页面下,最好写绝对路径

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-21
直接用html代码跳转,减少js的办法,也是很容易的
稍微改了下,不知道符不符合你的要求,颜色可自拟
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>5秒后跳转到另一个页面</title>
</head>
<script>
var t = 5;
var s = '.';
timeID=setInterval("countDown()",1000);
function countDown(){
time.innerHTML= t +"秒后跳转"+s;
t--;
s+='.';
if (t==0) {
location.href="http://www.tc345.cn/"; //【你要跳转到的目标网站】
clearInterval(timeID);
}
}
</script>
<body>

<div><font ID="time" face="impact" color="#272822" size="5">即将跳转</font>
</div>
</body>
</html>
只要修改对应的跳转链接就可以了,打开后五秒跳转