...

View Full Version : Refresh a page at a specific time of day



nite1x
01-02-2005, 07:07 PM
This may be a stupid question, but is there a way to have a page refreshed at a specific time of day?
I have made up a page I set as my browser's home page, an electronic Page-A-Day calendar. If I am working on the computer overnight I would like this page to refresh autotically at midnight. I have seen all sorts of posts that describe how to refresh after a certain amount of time has passed, but nothing for what I would like to do.

For those interested the code i have for the webpage in in the attached file.

Nite

mark87
01-02-2005, 07:25 PM
Hmm well you could get a script which places the time in a text box (I suppose it could be hidden), then write an if statement for when the text is changed that checks if the text is '00:00' then if it is then the page is refreshed. :)

Brandoe85
01-02-2005, 07:31 PM
You could use the Date object, and get the current time, and when it hits midnight you can do a refresh. I allready had this script made up, you wouldn't need to convert it to AM PM you could use the sytem time. This is just an example, to give ya an idea.


<html>
<head>
<title></title>
<script type="text/javascript">
function getCurrentTime()
{
var myDate = new Date();
var mySecs = myDate.getSeconds();
var curHour = myDate.getHours();
var curMin = myDate.getMinutes();
var suffix = "AM";

if(mySecs < 10)
mySecs = "0" + mySecs;

if(curMin < 10)
curMin = "0" + curMin;

if(curHour == 12 && curMin >= 1)
{
suffix = "PM";
}
if(curHour == 24 && curMin >= 1)
{
curHour-= 12;
suffix = "AM";
}
if(curHour > 12)
{
curHour-= 12;
suffix = "PM";
}

var time = curHour + ":" + curMin + ":" + mySecs + " " + suffix;
document.getElementById('time').innerHTML=(time);

if(time == "12:00:00 AM") //Change this to whatever time you want
location.reload();

}
</script>
</head>
<body onload="setInterval('getCurrentTime()', 1000);">
<div id="time"></div>
</body>
</html>

nite1x
01-02-2005, 07:55 PM
Thanks Brando, looks like this will do the trick.

Will keep you posted.

Nite

Brandoe85
01-02-2005, 08:02 PM
You're welcome, post back if you get stuck on anything :)

nite1x
01-02-2005, 08:40 PM
It worked perfectly, I even decided to incorporate the clock into the page.

Nite

Brandoe85
01-02-2005, 08:46 PM
Great, I'm glad it all worked out :thumbsup:

jsarber
11-21-2009, 09:16 PM
I have been looking to do the same thing but this script does not work for me. Is the time based on the user's time or the server's time? Also, will it work on a php page?

Rowsdower!
11-22-2009, 02:32 AM
Random interjection here, but would it be better to check the time ONCE on the page load to get the current time and then set a timeout for the remaining seconds between then and midnight? It would avoid a time re-check every second (or minute, or whenever)...

it career
11-22-2009, 04:29 AM
Random interjection here, but would it be better to check the time ONCE on the page load to get the current time and then set a timeout for the remaining seconds between then and midnight? It would avoid a time re-check every second (or minute, or whenever)...

That would it be better.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum