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 10 of 10
  1. #1
    New Coder
    Join Date
    Dec 2004
    Location
    Ontario, Canada
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Refresh a page at a specific time of day

    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
    Attached Files Attached Files

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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.
    Code:
    <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>
    Last edited by Brandoe85; 01-02-2005 at 09:02 PM. Reason: Can't spell

  • #4
    New Coder
    Join Date
    Dec 2004
    Location
    Ontario, Canada
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Brando, looks like this will do the trick.

    Will keep you posted.

    Nite

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You're welcome, post back if you get stuck on anything

  • #6
    New Coder
    Join Date
    Dec 2004
    Location
    Ontario, Canada
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It worked perfectly, I even decided to incorporate the clock into the page.

    Nite

  • #7
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Great, I'm glad it all worked out

  • #8
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    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)...
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #10
    Banned
    Join Date
    Jun 2007
    Location
    Web Designer
    Posts
    321
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Rowsdower! View Post
    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.


  •  

    Posting Permissions

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