Coundown timers

Discussion in 'JavaScript' started by kadi, Aug 6, 2013.

  1. #1
    how can i add a coundown timer of say 30 sec . since i am using a coundown timer which is not working as i require. i got two pages and when i run the code, the timer already started and running in background on page 1 and in page 2 there is no countdown timer showing. i dont know how to achieve my task of showing countdown timers like a game timer for my 2 pages...
     
    kadi, Aug 6, 2013 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    538
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    Untested, but is it something like this one?
    <script>
    var
      counter = 30;
      counterID = setInterval( function(){
        counter--;
        if (counter >0){
          //do something here
        }
        else
          clearInterval(counterID);
      }, 1000);
    </script>
    HTML:
     
    hdewantara, Aug 6, 2013 IP
  3. juggalox

    juggalox Member

    Messages:
    152
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #3
    You need to really be more clear in what you post. It's vague but from what I understand , you are trying to retain the countdown timer value from page1 into page2?
    That means you need some sort of communication between the 2 pages. If it's a parent-pop down system , then it's not that difficult.

    You could also use window object , but it's an unsecure way. You can accomplish this by using some server side scripting , say PHP , by doing a polling ajax request in javascript , but that might causelag. The new HTML5 api provides a method but not all browsers support it. Last , you can use cookies which is the old fashioned way.

    Take a look at this , it might help :
    http://bytes.com/topic/javascript/i...tion-between-browser-windows-tabs#post3662701
    http://davidwalsh.name/window-postmessage
     
    juggalox, Aug 9, 2013 IP