Js code that jumps to another page after 5 seconds

  • 2020-03-26 21:26:04
  • OfStack

 
<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
<title>5 It jumps to another page in seconds </title> 

<script type="text/javascript"> 
var t = 5; 
function countDown(){ 
var time = document.getElementById("time"); 
t--; 
time.value=t; 
if (t<=0) { 
location.href="http://www.baidu.com"; 
clearInterval(inter); 
}; 
} 
var inter = setInterval("countDown()",1000); 
//window.onload=countDown; 
</script> 

</head> 
<body onload="countDown()"> 

<input type="text" readonly="true" value="5" id="time"/> 

<!-- I could also write it here javascript Code so you don't have to body Label in writing onload="countDown()" . --> 
</body> 
</html> 

Related articles: