Web Analytics Made Easy -
StatCounter Timed webpage refresh, using host time - CodingForum

Announcement

Collapse
No announcement yet.

Timed webpage refresh, using host time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    This sounds to be best done with javascript.
    Moving from Java forum to Javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      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; Aug 25, 2011, 03: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.

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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.

            Comment


            • #7
              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.
              Having said that, I've probably told you more than I know.

              Comment


              • #8
                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...
                Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

                Comment


                • #9
                  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.
                  Having said that, I've probably told you more than I know.

                  Comment


                  • #10
                    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

                    Comment


                    • #11
                      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).
                      Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

                      Comment


                      • #12
                        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

                        Comment


                        • #13
                          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; Aug 27, 2011, 03: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.

                          Comment

                          Working...
                          X
                          😀
                          🥰
                          🤢
                          😎
                          😡
                          👍
                          👎