Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Countdown Timer

  • 04-11-2010 06:47PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 21,279 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 21,279 ✭✭✭✭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, Registered Users 2 Posts: 2,626 ✭✭✭timmywex


    Lovely thanks very much!!


Advertisement