Javascript gmail storage counter

Discussion in 'JavaScript' started by dpEv, Nov 11, 2008.

  1. #1
    Hi all,

    I am looking for a counter like the one that gmail uses on their homepage, which continually adds to the amount free storage across the gmail email network.

    Preferably javascript but i am also interested in other programming languages including flash that might be able to provide the same functionality.

    The Gmail counter basically works by calculating dates and a particular amount of storage to go up by between those dates.

    Thanks in advance.
     
    dpEv, Nov 11, 2008 IP
  2. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Considering that only the server can know the current value of the metric you're visualizing with the counter, i'd have the php that spits out your page include the counter as

    PHP inline HTML, text in a .php file but outside <?php and ?>:
    
    My counter : <span id="counter"><?=$initialValue?></span> someMetric.
    
    Code (markup):
    Then include a javascript function at the end of your document, just before </body>, that's sorta like this:

    PHP inline HTML:
    
    <script language='JavaScript1.3' type='text/javascript'><!--
    function calculateNewValue() {
      var span = document.getElementById ('counter');
      var value = parseInt (span.innerHTML);
      value += incrementPerSecond;
      span.innerHTML = value;
      setTimeout (calculateNewValue, 1000);
    };
    
    var incrementPerSecond = <?=$incrementPerSecond?>;
    calculateNewValue();
    --></script>
    
    Code (markup):
     
    rene7705, Nov 12, 2008 IP
  3. avim1

    avim1 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I tried the code but it seems to me that something bad is it, if you can fix it or get something that works I will be happy.
     
    avim1, Jan 14, 2010 IP