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
    New Coder
    Join Date
    Jun 2012
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts

    refresh on hour every hour help

    h i appreciate if someone can help me solve this. want to make this load the data at won.php every hour on the hour that will update the next program start for our radio station at vikingradio192.com so far we have this code that refreshes and loads every 30 seconds and not really suitable

    jQuery(document).ready(function($){
    (function whatsOnNow() {
    $('#whatsOnNow').load('/whatsOnNow/won.php', function() {
    setTimeout(whatsOnNow, 5000);
    });
    })();
    });



    many thanks in advance


    Ron

    www.vikingradio192.com

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    5000 milliseconds is 5 seconds, not 30 seconds.

    There are 3600000 millseconds in one hour.


    To refresh every hour on the hour (within one second) you will need:-

    Code:
    <script type = "text/javascript">
    
    function timer() {
    var now = new Date();
    var mins = now.getMinutes();
    var secs = now.getSeconds();
    if ((mins == 0) && (secs == 0)) {
    window.location.href = // refresh your page
    }
    }
    
    function checktime() {
    window.setInterval(timer,1010);  // every 1.01 seconds
    }
    
    checktime()
    </script>
    Last edited by Philip M; 02-12-2014 at 08:40 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,925
    Thanks
    56
    Thanked 549 Times in 546 Posts
    the only problem with Philip's code is that it works off the user's computer's time - so if they have their clock set to 10:30, it will be half an hour until the page refreshes, even though it may really be 10:59

    if you are calling a php page you can use that file to echo in the server time, get that as a javascript variable and then calculate the minutes/seconds left until the next load should take place


  •  

    Posting Permissions

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