Three common methods for automatic jump of HTML pages after 3 seconds: automatic page Jump
In practice, we often encounter a problem: how to automatically jump to a page N seconds later?
I have encountered problems and searched for information, and summarized three methods.
Method 1:
The simplest one is to add Code directly in the previous
<Span style = "font-size: 18px;"> </span> <span style = "font-size: 24px; "> <meta http-equiv =" refresh "content =" 3366url+res.html "> </span> <span style =" font-size: 24px; "> // automatically redirects to res.html in 3 seconds, to jump to the jsp page under the same file, you need to enter the url address ---- (the data written in the address bar of the browser, such as http: // localhost: 8080/TestDemo/1.jsp) </span>
Method 2:
The method in window must be used:
SetTimeout calculates an expression after a specified millisecond value.
Example:
window.setTimeout("alert('Hello, world')", 1000);
This is written in js Code;
The specific implementation is as follows:
<Script type = "text/javascript"> onload = function () {<span style = "white-space: pre "> </span> // load the setTimeout (go, 3000) method when entering the webpage; <span style =" white-space: pre "> </span>/* unit of ms in js */}; function go () {location. href = "http: // localhost: 8080/TestDemo/index. jsp ";}</script> // After 3 seconds, the go method is automatically executed to directly jump to the index. jsp page
Method 3:
The disadvantage of the above two examples is that the jump can be implemented, but I don't know when the jump will be implemented. The countdown is 3-2-1;
The settimeout method is no longer available;
SetInterval calculates an expression after a specified millisecond value.
After the same time, the corresponding function will be executed. Specific implementation methods:
<Script type = "text/javascript"> onload = function () {setInterval (go, 1000) ;}; var x = 3; // use global variables to execute function go () {x --; if (x> 0) {document. getElementById ("sp "). innerHTML = x; // The value of x set each time is different. } Else {location.href}'res.html ';}}</script>
The above content is the three common methods to automatically jump to an HTML page 3 seconds later. I hope you will like it and will help you and enjoy it.