HTML page-------3 common implementations of auto-jump after 3 seconds

Source: Internet
Author: User

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>

SetTimeout

HTML page-------3 common implementations of auto-jump after 3 seconds

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.