JavaScript implementation countdown jump page _javascript Tips

Source: Internet
Author: User
Many web pages have a similar effect, that is, after a specified time to jump to other pages, if the humanization of a little words, will have a countdown effect, this chapter describes how to achieve this effect, code examples are as follows:

<script type= "Text/javascript" > 
var t=10;
SetInterval ("refer ()", 1000); 
function refer () { 
 if (t==0) { 
 location.href= "http://www.jb51.net";
 } 
 document.getElementById (' show '). Innerhtml= "+t+" seconds later jump to cloud-dwelling community ";
 t--;
} 
</script> 
<span id= "Show" ></span> 
The above code to achieve the desired effect, can be in 10 seconds to jump to the specified page, the following introduction to the implementation process.
I. Principle of realization:
The principle is very simple, is to use the setinterval () Timer function, every second to perform a refer () function, this function can not perform a T minus 1, while the current T value to write Div, if T to 0, that is, the countdown is complete, jump to the specified page. The principle is roughly the same.
Two. Related reading:
The 1.setInterval () function can refer to the SetInterval () section of the functional usage.
2.location.href can refer to the HREF attribute section of the Location object.
The 3.innerHTML attribute can refer to the usage section of the innerHTML property of JS.

below to share 2 simple jump code, do a summary, a variety of timing jump code records are as follows:

(1) using the SetTimeout function to achieve a timed jump (the following code to write in the body area)

<script type= "Text/javascript" > 
//3 seconds later jumps to the specified page 
settimeout (window.location.href= ' http:// Www.jb51.net ', 3); 
</script> 

(2) HTML code implementation, the page in the head area of the block with the following code

<!--5 Seconds to jump to the specified page--> 

Related Article

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.