_javascript technique of timing jump to specified page based on JavaScript implementation

Source: Internet
Author: User
Tags numeric value setinterval

In some scenarios, the page after the specified time, the page can automatically jump to the specified page, such as when the specified page can not be found, will display the previous set of 404 pages, and jump to the specified page, the following is a piece of code to achieve this effect.

The code is as follows:

 <! DOCTYPE html> 

The above code, you can jump to the specified page in three seconds, the following is a brief introduction to the implementation process.

I. Principle of realization:

Using the Timer function, the number of the span element is modified every second, and when the number reaches 0, the page jumps to the specified link, and the principle is roughly the same.

Two. Code comments:

1.function Redirect () {}, declaring a vague, for jump.
2.if (second<0) {location.href= ' http://wwww.jb51.net ';}, if the number is less than 0, it jumps.
3.else{}, otherwise the countdown effect.
4.if (Navigator.appName.indexOf ("explorer") >-1) to determine if it is IE browser.
5.document.getelementbyid (' Totalsecond '). innertext=second--, if it is an IE browser, use the InnerText property to set the numeric value in the SPAN element.
6.document.getelementbyid (' Totalsecond '). textcontent=second--, other browsers use the Textcontent property to set numeric values in the SPAN element.
7.window.onload=function () {} to execute the code in the function when the document is completely loaded.
8.if (Navigator.appName.indexOf ("explorer") >-1) {}, and if it is an IE browser, use the InnerText property to get the contents of the SPAN element.
9.second = document.getElementById (' Totalsecond '). Textcontent, other standard browsers use the Textcontent property to get span element values.
10.setInterval ("redirect ()", 1000), performs a timer function every second.

Three. Related reading:

The 1.indexof () function can refer to the LastIndexOf () method in JavaScript using the detailed chapter.
The 2.setInterval () function can refer to the chapter on the use and difference examples of setinterval () and settimeout ().

The above content is small set for everyone to share based on the JavaScript implementation timer jump to the specified page of all the narrative, I hope you like.

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.