Sometimes, when users access an incorrect or inaccessible page, we can do something like this: Countdown n seconds to jump to another page or back to the previous page.
You can go to the demo page to view the effect!
This effect can be achieved using JavaScript:
Html
1 <p> 2 <span id = "timer"> </span> seconds after the automatic return 3 <a href = "http://www.qianduanzu.com/"> jump directly </a> 4 </ p>
Javascript
1 window. onload = function () {2 var time = 3; // set the time to seconds. 3 var timer = document. getelementbyid ('timer'); // obtain the object 4 timer whose ID is timer. innerhtml = time; // initialization display seconds 5 time = Time-1; 6 var G = Window. setinterval (function () {7 if (time <0) {8 window. cleartimeout (g); // clear the animation 9 window. location. href = 'HTTP: // www.qianduanzu.com/'; // jump to the specified address 10 // window. history. back (-1); // back 11} else {12 Showtime (); 13} 14}, 1000); 15 // display function 16 function Showtime () {17 timer. innerhtml = time; 18 time --; 19} 20 };
If you do not want to perform such an animation, you can directly implement it using HTML, as shown below:
1 <meta http-equiv="refresh" content="3;url=http://www.qianduanzu.com/">
Author: front-end group