In practice, we often encounter a problem is how to implement the page n seconds after the automatic jump?
I ran into problems and looked up data and summed up 3 ways
Method 1:
The simplest: Add code directly to the front
<span style= "FONT-SIZE:18PX;" > </span><span style= "FONT-SIZE:24PX;" ><meta http-equiv= "Refresh" content= "3; Url=res.html "> </span>
<span style= "FONT-SIZE:24PX;" >//3 seconds after the automatic jump to res.html, two belong to the same file, if you need to jump to the JSP page, you need to fill in the URL address ———— (the address bar of the browser to write data, such as: http://localhost:8080/ testdemo/1.jsp) </span>
Method 2:you need to use the method inside the window:
SetTimeout |
Evaluates an expression after the specified millisecond value. |
Example:
Window.settimeout ("alert (' Hello, World ')", 1000);
This is written in the JS code inside;The specific implementation is as follows:
<script type= "Text/javascript" >onload=function () { <span style= "White-space:pre" ></span>// Load the method settimeout (go, 3000) when entering the Web page; <span style= "White-space:pre" ></span>/* in JS is the unit of Ms */};function Go () {location.href= "http://localhost : 8080/testdemo/index.jsp "; }</script>
3 seconds after the Go method is automatically executed, jump directly to the index.jsp page
Method 3:the drawback of the above two examples is the ability to jump, but do not know when to jump. Achieve the reciprocal 3-2-1;
the SetTimeout method has not been done;
SetInterval |
Evaluates an expression after each specified millisecond value. |
without the same time, the corresponding function will be executed. The specific implementation method:
<script type= "Text/javascript" >onload=function () {setinterval (go, 1000);}; var x=3; A global variable is used 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>
HTML page-------3 common implementations of auto-jump after 3 seconds