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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Countdown Timer

  • 04-11-2010 6: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,263 ✭✭✭✭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,263 ✭✭✭✭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