Some common javascript code to share

  • 2020-03-30 02:26:40
  • OfStack

Return automatically after 1.3 seconds
 
<span id="totalSecond">3</span> Return automatically after seconds  

<script language="javascript" type="text/javascript"> 
<!-- 
var second = document.getElementById('totalSecond').textContent; 
if (navigator.appName.indexOf("Explorer") > -1) //To determine whether it is Internet explorer or Firefox, take the appropriate measures to obtain the number of seconds
{ 
second = document.getElementById('totalSecond').innerText; 
} else 
{ 
second = document.getElementById('totalSecond').textContent; 
} 
setInterval("redirect()", 1000); //The redirect() method is invoked every 1 second
function redirect() 
{ 
if (second < 0) 
{ 
location.href = 'http://www.baidu.com'; 
} else 
{ 
if (navigator.appName.indexOf("Explorer") > -1) 
{ 
document.getElementById('totalSecond').innerText = second--; 
} else 
{ 
document.getElementById('totalSecond').textContent = second--; 
} 
} 
} 
--> 
</script> 

Related articles: