Forum Moderators: open

Message Too Old, No Replies

HTML Dynamic Webpage refreshing?

         

gdrobson

4:49 pm on Oct 13, 2003 (gmt 0)



Hi,

I am trying to create a webpage that displays events, and from time to time the webpage is updated. When it is updated I want it to automatically update all the clients viewing the webpage with a refresh, but only when it is updated.

I know I can add this into the header of the webpage "<META HTTP-EQUIV=Refresh CONTENT=30>", and the clients will update every 30 seconds, but this is not efficient in my opinion.

All suggestions are welcome.

garann

6:47 pm on Oct 13, 2003 (gmt 0)

10+ Year Member



Welcome to Webmaster World, gdrobson. :)

I think you're going to have a hard time doing what you suggest. If you want a page downloaded by the client to check for updates on the server it came from, something on that page is going to have to make a request every 30 seconds (or other period).

I tried to find a way to query files in JavaScript, but came up blank. document.location does have a property called hash, but that's not a hash of the page, which would tell you whether its content has changed. Maybe someone else knows a method?

I'd recommend putting whatever content needs to update in an iframe or something - even an invisible frame that causes a reload of the main page - since it seems like HTTP requests are going to be the easiest way to go. You can then use a META refresh just on that page, and check whether your content has been updated using querystrings or something.

hth,
g.

tedster

9:07 pm on Oct 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's the main issue I see: How would you know whow is "viewing the page"?

All you know is that someone requested the page - but within just a few seconds of that request, the window could be closed, or showing a different page or a different website.

SethCall

10:05 pm on Oct 14, 2003 (gmt 0)

10+ Year Member



There is a solution that is rather involved, but more appropriate... do a search on http push. The good thing about this technology/hack is that there are a decent number of options.

Other option

Harder part:
In your server-side script, you are going to have to have access to how long it is before you next forced refresh. Depending on what this event is, this could be hard.

Once you have that value, it should be rather easy:... when outputting your page with your script, in the header, in your script tag, do something like.

function blah()
{
[server script outputs here:]

setTimeout(window.refresh, HOW_LONG_TO_WAIT);
}

<body onload="blah();">

window.refresh is pseudo javascript: im not that familiar with js off the top of my head.