JS implementation of the page after a few seconds automatically jump to the specified URL

Source: Internet
Author: User

Search on the Internet, about this technology to deal with a variety of methods, I only note that I learned in the video three kinds:

1, with a response.sendredirect ("target page. jsp\.htm"); achieve direct jump;

2, sometimes we need a little hint, such as "X seconds after the automatic jump, if not jump, click here", you can call the delay in the myeclipse snippets in the Go to URL. The following code is automatically generated:

The code is as follows:

<script language= "JavaScript1.2" type= "Text/javascript" >

<!--

Place the the ' Head ' section of your page.

function Delayurl (URL, time) {

SetTimeout ("top.location.href=" + URL + "'", time);

}

-

</script>

<!--Place the "Body" section---

<a href= "javascript:" onclick= "Delayurl (' mypage.html ', ' a ')" >my Delayed link</a>

Modify this code to:

The code is as follows:

<script language= "JavaScript1.2" type= "Text/javascript" >

function Delayurl (URL, time) {

SetTimeout ("top.location.href=" + URL + "'", time);

}

</script>

<span id= "Time" style= "background:red" >3</span>

Seconds after the automatic jump, if not jump, please click the link below

<a href= "target page. jsp" > target page </a>

<script type= "Text/javascript" >

Delayurl ("http://www.ablanxue.com", 3000);

</script>

You will then jump directly to the target page after 3 seconds. This method is set to jump after a few seconds in the process of the page will not change, for example, set 3 seconds, and then change over time 3 into 2 and then into 1 until jump, see the third method below.

3. Modify the code in Method 2 to:

The code is as follows:

<script language= "JavaScript1.2" type= "Text/javascript" >

function Delayurl (URL) {

var Delay=document.getelementbyid ("Time"). InnerHTML;

The last innerHTML cannot be lost, otherwise the delay is an object

if (delay>0) {

delay--;

document.getElementById ("Time"). Innerhtml=delay;

}else{

Window.top.location.href=url;

}

SetTimeout ("Delayurl ('" + URL + "')", 1000);

Here 1000 milliseconds to jump once per second

}

</script>

<span id= "Time" style= "background:red" >3</span>

Seconds after the automatic jump, if not jump, please click the link below

<a href= "target page. jsp" > topic list </a>

<script type= "Text/javascript" >

Delayurl ("http://pic.ablanxue.com");

</script>

The effect of this method is to jump to this page after clicking Submit on the previous page after 3 seconds (this 3 will be decremented to 0) after jumping to the target page.

JS implementation of the page after a few seconds automatically jump to the specified URL

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.