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:
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.