Javascript automatically redirects to the code after the countdown N seconds

Source: Internet
Author: User

Javascript automatically redirects to the code after the countdown N seconds

Copy codeThe Code is as follows:
<Title> JS countdown webpage automatic jump Code </title>
<Script language = "JavaScript" type = "text/javascript">
Function delayURL (url ){
Var delay = document. getElementById ("time"). innerHTML;
If (delay> 0 ){
Delay --;
Document. getElementById ("time"). innerHTML = delay;
} Else {
Window. top. location. href = url;
}
T = setTimeout ("delayURL ('" + url + "')", 1000 );
}

Function stop1 (){
T & clearTimeout (t );
}
</Script>
<Span id = "time" style = "background: #00 BFFF"> 1000 </span> is automatically redirected in seconds, click the link below <a href = "http://www.baidu.com"> my Baidu </a>
<Input type = "button" value = "Stop Jump" onclick = "stop1 ();">
<Script type = "text/javascript">
DelayURL ("http://www.baidu.com ");
</Script>

The code is very simple, but it is very practical. You can put it in your project as needed.

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.