Google Answers Logo
View Question
 
Q: Conditional refresh of javascript HTML based on content changes ( No Answer,   2 Comments )
Question  
Subject: Conditional refresh of javascript HTML based on content changes
Category: Computers > Programming
Asked by: clb108-ga
List Price: $10.00
Posted: 06 Nov 2005 20:15 PST
Expires: 07 Nov 2005 11:33 PST
Question ID: 589955
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

Clarification of Question by clb108-ga on 07 Nov 2005 11:33 PST
I found out that this can't be done within javascript
Answer  
There is no answer at this time.

Comments  
Subject: Re: Conditional refresh of javascript HTML based on content changes
From: scorpion_-ga on 06 Nov 2005 21:22 PST
 
var numSeconds = 2;
var inter = window.setInterval("checkTimestamp()", numSeconds * 1000);

function checkTimestamp() {
  if (xxxxxxxxxxxxxxxxxxxxxxx) {
    location.reload();
    window.clearInterval(inter);
  }
}

xxxxxxxxxx should be replaced with the check of the timestamp.  If you
clarify the requirements, I can tell you how to check it.  Also, I did
not try the above code, so if it generates an error let me know. 
Might be some oversight on my part.

- Michael Shmulenson
Subject: Re: Conditional refresh of javascript HTML based on content changes
From: clb108-ga on 06 Nov 2005 21:44 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.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy