...

View Full Version : Timed webpage refresh, using host time



fill0000
08-24-2011, 12:00 PM
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 :thumbsup:

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!!

Fou-Lu
08-24-2011, 02:22 PM
This sounds to be best done with javascript.
Moving from Java forum to Javascript forum.

Philip M
08-25-2011, 07:59 AM
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
$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".

webdev1958
08-25-2011, 08:27 AM
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.

Philip M
08-25-2011, 08:31 AM
You mention sending back a boolean yet your code is sending back a string.

Alas, slip of the keyboard. :o But as you say, a string will work just as well.

fill0000
08-25-2011, 03:03 PM
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.

jalarie
08-25-2011, 10:16 PM
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.

rnd me
08-25-2011, 10:51 PM
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...

jalarie
08-25-2011, 11:07 PM
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.

fill0000
08-26-2011, 12:07 PM
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

rnd me
08-26-2011, 04:55 PM
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).

Rowsdower!
08-26-2011, 05:40 PM
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.

Philip M
08-27-2011, 08:40 AM
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".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum