JavaScript Countdown Jump Page Instance

Source: Internet
Author: User

In JS to achieve page timing jump we want to use the SetInterval or settimeout function, of course, you can also use the Metea implementation of the page, I introduce the following two examples.

Example 1

Countdown Refresh Page

The code is as follows

<script type= "Text/javascript" language= "JavaScript" >

var starttime = new Date ();
var endtime=starttime.gettime () +10*60*1000;
var g_blinkswitch = 0;
var g_blinktitle = Document.title;
function Getremaintime () {

var nowtime = new Date ();
var NMS =endtime-nowtime.gettime ();
var Nm=math.floor (nms/(1000*60))% 60;
var ns=math.floor (nms/1000)% 60;
if (nm==0&&ns==0&&nms<1000)//When the countdown is over
{
Window.focus ();
SetInterval ("blinknewmsg ()", 1000);
Window.location.reload ();
}
if (ns < NS) = "0" + ns;

if (NMS >= 0) {
document.getElementById ("Remaintime"). Innerhtml= NM + "min" + NS + "seconds";

SetTimeout ("Getremaintime ()", 1000);
}

}

function blinknewmsg ()
{
Document.title = g_blinkswitch% 2==0? ""-"+ G_blinktitle:" "New Message"-"+
G_blinktitle;
g_blinkswitch++;
}


Window.onload=getremaintime;

</script>

<strong id= "Remaintime" >10 minute 00 sec </strong>

Example 2

Countdown Jump Page

The code is as follows

<TITLE>JS Countdown page Auto Jump code </title>
<script language= "JavaScript" type= "Text/javascript" >
function Delayurl (URL) {
var delay = document.getElementById ("Time"). InnerHTML;
if (Delay > 0) {
delay--;
document.getElementById ("Time"). InnerHTML = delay;
} else {
Window.top.location.href = URL;
}
SetTimeout ("delayurl (' + URL + ')", 1000);
}
</script>
<span id= "Time" style= "background: #00BFFF" >3</span> seconds after automatic jump, if not jump, please click the link below <a href= "http:// Www.45it.com "> My Baidu </a>
<script type= "Text/javascript" >
Delayurl ("http://www.45it.com");
</script>

Anti-Refresh Countdown code

The code is as follows

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> 
<title> www.45it.com</title> 

<body >&NBSP
<script language= "JavaScript" > 
<!-- 
var maxtime; 
if ( window.name== ') { 
MaxTime = 1*60; 
}else{ 
MaxTime = window.name; 
} 
function countdown () { 
if (maxtime>=0) { 
minutes = Math.floor (MAXTIME/60);  
seconds = Math.floor (maxtime%60);  
msg = distance to the end of the exam there is also "+minutes+" +seconds+ "seconds";  
document.all["Timer". InnerHTML = msg; 
if (maxtime = = 5*60) alert (' Note, there are 5 minutes! '); &NBSP
--maxtime; 
Window.name = maxtime; 
} 
else{ 
ClEarinterval (timer);  
Alert ("Test time to, end!"); &NBSP
} 
} 
Timer = SetInterval ("Countdown ()", 1000);  
//-->
</SCRIPT> &NBSP
<div id= "Timer" style= "color:red" ></DIV>&NBSP;
</body> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.