Web Analytics Made Easy -
StatCounter Countdown to page refresh - CodingForum

Announcement

Collapse
No announcement yet.

Countdown to page refresh

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Countdown to page refresh

    Hi Guys,

    Our company own a lot of domains and want to put a short page of copy on each address along with keywords before redirecting the user to our main site.

    I have been able to get the page to load the main site after the desired time using this code in the head...

    <META HTTP-EQUIV="refresh" CONTENT="40;URL=http://webaddress.com/">
    That works perfectly, I am now trying to display a countdown timer from 40 seconds down to 0, and on 0 redirect the user. Saying something like "You will be redirected in XX seconds".

    Is there anyway of doing this? I've been searching google for the answers with no luck and can only seem to find timers that countdown to a set date.

    Thanks in advance!
    Ria

  • #2
    Put this code into the <body>
    Code:
    <div id="countdown"></div>
    <script type="text/javascript">
    var duration = 40;
    showDuration();
    
    function showDuration() {
       document.getElementById('countdown').innerHTML = "You will be redirected in " + duration + " seconds";
       duration--;
       window.setTimeout(showDuration, 1000);
    }
    
    </script>

    Comment


    • #3
      Code:
      <div id="countdown"></div>
      
      <script type="text/javascript">
      
      var duration = 40;
      showDuration();
      
      function showDuration() {
      document.getElementById('countdown').innerHTML = "You will be redirected in " + duration + " seconds";
      duration--;
      if (duration >=0) {
      window.setTimeout(showDuration, 1000);
      }
      else {
      window.location.href = "http://www.google.com";
      }
      }
      
      </script>

      Quizmaster: What is the name of the river that runs through Rome?
      Contestant: The Nile.
      Last edited by Philip M; Aug 22, 2011, 08:48 AM.

      All the code given in this post has been tested and is intended to address the question asked.
      Unless stated otherwise it is not just a demonstration.

      Comment


      • #4
        @Philip_M He already has the page refresh in his META tag ... but nevertheless, your code will work fine, too

        Comment


        • #5
          Originally posted by devnull69 View Post
          @Philip_M He already has the page refresh in his META tag ... but nevertheless, your code will work fine, too
          Oh, sorry, I did not notice the META tag. And I left the <div> out.

          All the code given in this post has been tested and is intended to address the question asked.
          Unless stated otherwise it is not just a demonstration.

          Comment


          • #6
            Originally posted by Philip M View Post
            Oh, sorry, I did not notice the META tag. And I left the <div> out.
            In case you don't know what the meta tag does, this explanation might help.

            Comment


            • #7
              Excellent! Thanks guys! DevNull69 your code works perfectly and does just what I need it to do! Many thanks, Philip M - I'm not quite sure how yours is different? Thanks all the same

              Comment


              • #8
                Philip's code added the refresh part to Javascript, so you could as well use his code and remove the META tag

                Comment


                • #9
                  ok here's another stupid question...

                  How do I style up the text? I can't use <p> tags can I?

                  Thanks!

                  Also it would be able to put a link in there too... "if you are not redirected click here"

                  Many thanks

                  Comment


                  • #10
                    You can use any string that produces valid HTML ...

                    Comment


                    • #11
                      I knew it was a stupid question! Thanks for your help

                      Comment


                      • #12
                        oh wait sorry! Just tryed to include a link with no luck... I think it dislikes the <a> tags and "

                        if you are not redirected <a href="http://site.com">please click here </a>

                        Comment


                        • #13
                          Because
                          Code:
                          "<a href="linkpage.html">"
                          is not a valid string, whereas
                          Code:
                          "<a href=\"linkpage.html\">"
                          or
                          Code:
                          '<a href="linkpage.html">'
                          is

                          Comment


                          • #14
                            SUCCESS! Thanks mate!

                            Comment

                            Working...
                            X