...

View Full Version : Conditional displays depending on time passing



joonstar
06-29-2004, 08:54 AM
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

trib4lmaniac
06-29-2004, 09:09 AM
<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>

glenngv
06-29-2004, 09:39 AM
Alternative:


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;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum