How to redirect with countdown

by skyvia
1 replies
  • WEB DESIGN
  • |
Hey everyone,

How to redirect by showing a countdown?

I have seen in many website, they redirect by showing a countdown. Is this possible to do only with HTML?

Thanks
#countdown #redirect
  • Profile picture of the author dassad
    Originally Posted by skyvia View Post

    Hey everyone,

    How to redirect by showing a countdown?

    I have seen in many website, they redirect by showing a countdown. Is this possible to do only with HTML?

    Thanks
    This one is easy and here it is:

    Place this in your HEAD section or call it from external file:

    Code:
    <script language='JavaScript'>
    var time = 10;
    var page = "http://YOURWEBSITE.COM";
    function countDown(){
    time--;
    gett("container").innerHTML = time;
    if(time == -1){
    window.location = page;
    }
    }
    function gett(id){
    if(document.getElementById) return document.getElementById(id);
    if(document.all) return document.all.id;
    if(document.layers) return document.layers.id;
    if(window.opera) return window.opera.id;
    }
    function init(){
    if(gett('container')){
    setInterval(countDown, 1000);
    gett("container").innerHTML = time;
    }
    else{
    setTimeout(init, 50);
    }
    }
    document.onload = init();
    </SCRIPT>
    And place this where you want the countdown to appear:

    Code:
    <span id='container'></span>
    You can add text before and after this code. In the first code in the first lines you can edit the countdown time (seconds) at VAR TIME and VAR PAGE where the visitor is redirected.

    Regards,
    daSSad
    {{ DiscussionBoard.errors[3746209].message }}

Trending Topics