Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Countdown Timer

Options
  • 04-11-2010 7:47pm
    #1
    Registered Users Posts: 2,626 ✭✭✭


    Hey,

    Does anyone have a code for countdown timer, for say 10 seconds from when the page is opened!?

    Ive been looking on google and can only find timers that count down to a specific date

    Anyone any help or a point in the right direction?

    Cheers!


Comments

  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    An on-screen timer, or a page refresh timer ?


  • Registered Users Posts: 2,626 ✭✭✭timmywex


    On screen timer!

    Have a page that people willl click onto, then it will redirect after say 15 seconds, looking for an on screen countdown to that?


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    This is very rough code, and could do with a bit of refactoring I'm sure, but it's a start:

    [html]
    <html>
    <head>
    <script type="text/JavaScript">

    if (window.attachEvent)
    {
    window.attachEvent("onload", doTimer);
    }
    else if (window.addEventListener)
    {
    window.addEventListener("load", doTimer, false);
    }

    function doTimer()
    {
    var x = setTimeout("setVal()", 1000);
    }

    function setVal()
    {
    var contents = new Number(document.getElementById("timer").innerHTML);
    contents = contents -1;
    document.getElementById("timer").innerHTML = contents;
    if (contents > 0)
    {
    doTimer();
    }
    else
    {
    alert("do redirection now");
    }
    }

    </script>
    </head>
    <body>
    Redirecting in: <span id="timer" >15</span>
    </body>
    </html>
    [/html]


  • Registered Users Posts: 1,771 ✭✭✭jebuz


    That is really over-complicating things for such a simple task. The following piece of code should redirect you to www.google.com in 5 seconds, modify it as required.
    <head>
    
      <script type="text/javascript">
        function doOnLoad() {
          setTimeout('window.location="http://www.google.com"', 5000);
        }
      </script>
    
    </head>
    
    <body onload="doOnLoad()">
    Your content here...
    </body>
    


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Yeah, or you could just use a meta tag instead and have no scripting, but the OP did specifically ask for a countdown timer, so there might be a good reason behind it :)


  • Advertisement
  • Registered Users Posts: 2,626 ✭✭✭timmywex


    Lovely thanks very much!!


Advertisement