Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Conditional displays depending on time passing

    Code:
     Trial code for understanding what I want to do
    
    <if 5 seconds are not passed since the page is opened>
    
    5 seconds are not passed yet.
    
    <if 5 seconds are passed and 10 seconds are not passed sine the page is opened>
    
    5 seconds are alread passed, but 10 seconds not yet.
    
    <if 10 seconds are passed since the page is opened>
    
    10 seconds are already passed. 
    </if>
    Is it possible?


    Thanks in Advance
    Get my greedy up

  • #2
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script type="text/javascript">
    <!--
    var play=false;
    function timeSince()
    {
      var now=new Date();
      if(!play)
      {
        play=true;
        start=now;
      }
      else
      {
        elapsed=now.getTime()-start.getTime();
    	document.getElementById("timeElapsed").innerHTML=seconds+' seconds since page was, but not '+(seconds+5)+'.';
      }
      setTimeout("timeSince()", 5000);
    }
    //-->
    </script>
    </head>
    
    <body onLoad="timeSince();">
    <div id="timeElapsed">Page loaded.</div>

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Alternative:
    Code:
    var timer=1;
    var elapsedTime=-1;
    function init(){
      elapsedTime++;
      if (elapsedTime<5){
         window.status=elapsedTime+' secs (5 secs has not passed yet)';
         //do something
      }
      else if (elapsedTime<10){
         window.status=elapsedTime+' secs (10 secs has not passed yet)';
         //do something
      }
      else {
         window.status=elapsedTime+' secs (10 secs has already passed)';
         clearTimeout(timer);
         timer=0;
         //do something
      }   
      if (timer) timer=setTimeout('init()', 1000);
    }
    
    window.onload=init;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •