Three common methods for automatic jump of HTML pages after 3 seconds: automatic page Jump

Source: Internet
Author: User

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.

Related Article

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.