I have a page that uses javascript to display chess games, eg. slugfest.org/sanluis
For a game that is already done, this works fine, but for a game that
is in progress, I want the page to update when a new move is made. I
know I can do an automatic refresh every NN seconds, but that has a
few problems.
The first problem is that it could very well refresh the page right
when the visitor is looking at a specific position, so the automatic
refresh should only happen when the visitor is looking at the last
move of the game. The other problem, not as big of one, is that when
the game is over it would be annoying for the page to automatically
refresh all the time.
The live uplink process is automatically uploading the updated files
to the server, so the action needed in the client browser is to have
it check to see if the file on the server has changed and if it has to
make sure that the visitor is still on the last move and reload the
page.
I guess, the check to see if the visitor is on the last move could be
done before the check for updated content.
I am thinking that there could be a loop on code that is checking for
timestamp every N seconds and comparing it to the last one and if it
has changed to check the current position on the page and then do a
page reload if appropriate.
I know how to program in C, but not in javascript, so an example HTML
that implements the loop and checking timestamp every N seconds and
then a conditional refresh would be what I need. |
Clarification of Question by
clb108-ga
on
06 Nov 2005 21:45 PST
I need the code to get the timestamp of a file, eg. "index.html", so
that when the index.html is overwritten, the timestamp changes and
that would trigger the check to see if the page should be refreshed.
I would imagine that there needs to be a lasttimestamp variable that
is checked against and updated. There also needs to be code to check
to see if the user has clicked away from the last move of the game. We
should only reload the page if they are on the last move and a new
move was played.
I got it to go to the last move with the following code:
<script LANGUAGE="JavaScript1.1">
<!--
javascript:c(0,-4);
//-->
</script>
So if we are in a state that is not what c(0,-4) creates, then we
should suppress the page reload. If we are in the state that c(0,-4)
creates, then we should do the reload, if index.html has been updated.
The HTML is at slugfest.org/sanluis
|