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 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Timed webpage refresh, using host time

    Hi Guys,

    I'm embarking on a new project - although I've hit a wall.

    I require a page to refresh at a scheduled date and time, several times a day.

    For example, I would like the web page to reload the index at 3:15PM

    So if anyone has the web page open during that time, it will automatically refresh for them.

    Timing is quite important so I would need the script to use the server (hosts) time and not the end users time.

    I am currently deciding on which server language to use, although Javascript is probably a suitable option? or would ajax be more the thing for this?

    The webpage must execute the refresh at the time 3:15pm, so no matter when someone visits the page, even if its hours before, it must refresh at that time.

    If anyone has any pointers on the best way to achieve this and what language to start with I am forever greatful

    I do a lot of image design work and although I have worked with a few coders in the past but I haven't gone too much into coding myself, but its something I'm going to take time to learn and get involved in, so I'm not looking for script hand outs here, mainly just a nudge in the right direction.

    Thank you guys!!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This sounds to be best done with javascript.
    Moving from Java forum to Javascript forum.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    The best way is probably to check the server time via an AJAX request every 30 seconds and if the time is an "update time" then refresh the page using Javascript. Then have a function on the server that will send back a boolean value that tells Javascript to refresh the page or not. You do not say what server language you are using but here is a PHP example-

    PHP Code:
    <?php
        $time 
    date('H:i');
        if(
    $time == '15:15'){
            echo 
    "true";
        }else{
            echo 
    "false";
        }
    ?>
    Note: Will users be annoyed if the page refreshes automatically while they are actually looking at it?


    Lady Astor said to Winston Churchill "If I was married to you, I would put poison in your whisky".
    To which Churchill replied "If I was married to you, I would drink it".
    Last edited by Philip M; 08-25-2011 at 08:26 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.

  • #4
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by Philip M View Post
    Then have a function on the server that will send back a boolean value that tells Javascript to refresh the page or not.
    You mention sending back a boolean yet your code is sending back a string. Did you write that code or did you copy and pasted it from somewhere?

    In any case, you can send back any string like "update" or "refresh" or whatever you like to tell the onreadystatechange handler to refresh the page.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by webdev1958 View Post
    You mention sending back a boolean yet your code is sending back a string.
    Alas, slip of the keyboard. But as you say, a string will work just as well.

    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.

  • #6
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi guys, thank you for your replys, i have been checking out aspx too and made something similar to what i want using that language, although I mite try with php and ajax to save on hosting costs.

    Thanks everyone, and yeah I needed the page to reload at a certain time as the page would otherwise by blank with no information, as its a timed update only when new information comes through.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    627
    Thanks
    1
    Thanked 20 Times in 20 Posts
    I would have whatever (php?) sends out the page include the time delay needed before the next reload. Then scripting on the page does everything automatically with no ajax nor any other resource-wasting activities.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 591 Times in 572 Posts
    you can print a meta refresh in every html page, the content attrib set to the # of seconds until the next refresh occours. you won't need javascript or ajax if you use meta...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    627
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by rnd me View Post
    you can print a meta refresh in every html page, the content attrib set to the # of seconds until the next refresh occours. you won't need javascript or ajax if you use meta...
    Excellent! Much better than my suggestion.

  • #10
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rnd me View Post
    you can print a meta refresh in every html page, the content attrib set to the # of seconds until the next refresh occours. you won't need javascript or ajax if you use meta...
    Only this is not what I was asking for

    It has to run off server time, the update time is critical, when i say critical i mean absolutely critical to the project working.

    I have achieved this using asp although I may go by the php ajax method to save on asp.net server costs.

    Thanks for your input

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 591 Times in 572 Posts
    Quote Originally Posted by fill0000 View Post
    Only this is not what I was asking for

    It has to run off server time, the update time is critical, when i say critical i mean absolutely critical to the project working.

    I have achieved this using asp although I may go by the php ajax method to save on asp.net server costs.

    Thanks for your input
    uhhh, yeah; your server prints the number of seconds individually for each user. if the server doesn't use the server time, i don't know what does.

    it's exactly what you asked for.

    for example, if a refresh goes out at 3:30 :
    someone connecting at 3:29:30 gets a meta with "30" as the content.
    someone connecting at 3:19:30 gets a meta with "630" as the content.
    someone connecting at 3:00:43 gets a meta with "1757" as the content.


    if you need sub-second precision, you can use a real-time communication protocol like socket.io, coming to .net soon (here in alpha already).
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #12
    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
    The only benefit I see to the AJAX option would be keeping the user scrolled to the same spot in the page that they were in before when the content reloads. A meta refresh would be perfect if not for that.

    I saw rnd_me's post and thought to myself "A javascript-free solution? THAT'S FRIGGIN' PERFECT!" until I considered the possible page scrolling issue that would create. Prior to that I was thinking the exact same thing as jalarie had been (except to still make the refresh call with AJAX) and I was just skimming responses to see if it had already been mentioned before I chimed in. And basically it had been. Drats, foiled again!

    Anyway, if page scroll location is not an issue and you want to visibly refresh the page then I think the meta refresh is absolutely the best way to do this. A user's machine will not be so out of whack with its internal clock that it will miss the refresh deadline by much - if any - more time than the delay time of the AJAX request to get the server time in the first place.

    Otherwise, the method jalarie suggested is your next-best option, only do an AJAX refresh when the Timeout fires rather than a full page refresh. Don't run server checks every "x" seconds, just set up a Timeout from the beginning with the proper number of seconds specified by the server in javascript in the head of the document. It's easy, clean, and doesn't waste bandwidth or resources for your users or your server.

    In my mind choosing between these methods just comes down to finding the intended the meaning of "refresh" in your original post.
    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

  • #13
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by Rowsdower! View Post
    The only benefit I see to the AJAX option would be keeping the user scrolled to the same spot in the page that they were in before when the content reloads. A meta refresh would be perfect if not for that.
    That is why I asked the question "Will users be annoyed if the page refreshes automatically while they are actually looking at it?" The refresh is required "several times a day".
    Last edited by Philip M; 08-27-2011 at 08:48 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.


  •  

    Posting Permissions

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