Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hidden Alarm Clock? 2

Status
Not open for further replies.

dkirkdrei

Programmer
Dec 14, 2007
5
US
I have a page that will be displayed on a monitor continuously, 24 hours a day, 7days a week, 365 yada yada yada... I need to create a script that monitors system time and refreshes the browser every morning at 5:00am est. Can someone point me in the right direction?
 
Try one of the Javascript websites or do a Google search for "Javascript clock" and "Javascript refresh page"

Lee
 
Something like,

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
window.onload=clock();
function clock(){
var t,a,d=new Date();
t=d.toLocaleTimeString();
a=t.split(':');
t=a[0]+':'+a[1];
if(t>'04:59'){window.location='[URL unfurl="true"]http://point-to-myself.com';}[/URL]
setTimeout("clock()",10000);
}
</script>
</body>
</html>
 
MarkZK, I'll give you a star if you can point out the one major flaw with the code you posted.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
should be if(t=='05:00') ?, how about I give you a start for telling me ? :)
 
maybe this then,


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
window.onload=clock();
function clock(){
var t,a,d=new Date();
t=d.toLocaleTimeString();
a=t.split(':');
t=a[0]+':'+a[1]+':'+a[2].substr(0,9);
if(t>'15:19:30'){window.location='[URL unfurl="true"]http://point-to-myself.com';}[/URL]
setTimeout("clock()",1000);
}
</script>
</body>
</html>
 
sorry, pasted the wrong one somehow,

this ?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
window.onload=clock();
function clock(){
var t,a,d=new Date();
t=d.toLocaleTimeString();
a=t.split(':');
t=a[0]+':'+a[1]':'+a[2].substr(0,9);
if(t=='05:00:00'){window.location='[URL unfurl="true"]http://point-to-myself.com';}[/URL]
setTimeout("clock()",1000);
}
</script>
</body>
</html>
 
That is closer to what I was expecting, so a star for the effort. Your original code would have refreshed the page continuously throughout the day after 5:00am. Since the OP only wanted it to refresh once, your original code wouldn't have worked. Your latest post that checks to make sure it's equal to 5:00 will not have the problems that the original one did. The only problem with your most recent code is if the page gets caught up on a cycle where the timeout is called @ 4:59:99.999 and the cpu cycles used to perform the function take over a millisecond and bump the next time checked over to 5:00:01.000. Will it ever happen? Probably not, but it's possible that it could.

What I would do in this instance is pass a value in the querystring to the page. This value should determine the next day the page is refreshed.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var refreshDate = new Date([gray][i]date pulled from querystring[/i][/gray]);

window.onload = function () {
   window.setInterval("clock()",1000);
}

function clock(){
   var d = new Date();
   if (d.getTime() >= refreshDate.getTime()) {
      d.setDate(d.getDate() + 1)
      var newRefreshDate = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate() + " 05:00";
      window.location = "[URL unfurl="true"]http://server/page.html?refreshDate="[/URL] + newRefreshDate;
   }
}
</script>
</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Thanks for all the responses. I ended up using:
Code:
<script type="text/javascript">
    var reloadTime = "5:00:00"; 
    function startTime()
    {
	    var today=new Date();
	    var h=today.getHours();
	    var m=today.getMinutes();
	    var s=today.getSeconds();
	    
	    m=checkTime(m);
	    s=checkTime(s);
	    var time = h+":"+m+":"+s;
	    document.getElementById('txt').innerHTML=time;
	    if (time ==reloadTime)
	    {
		    window.location.reload()
	    }
	        t=setTimeout('startTime()',500);
        }
            function checkTime(i)
        {
	        if (i<10)
	    {
	        i="0" + i;
	    }
	        return i;
    }
</script>
and then in the html:
Code:
<body onload="startTime()">
<div id="txt" ></div>
I have the div's display set to none with css so that the clock does not show on the screen
 
Using indentation that does not make any sense is just as helpful as not using indentation at all....


CS101 folks, we should have all learned this a long time ago...

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top