Hi there,
AFAIK, there is no way that your web page can know when a remote file is updated.
What you could do however, is write a function that loads the contents of the text file into a predefined div using AJAX.
You could repeat this at a predefined interval.
Using AJAX would not be so heavy on the server and would avoid the ugly page flicker you described.
Here's an example:
HTML Code:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
// load text file when page loads
$("#div1").load("test.txt");
// Then reload it every 5 seconds, for ever ...
setInterval(function(){
$("#div1").load("test.txt");
}, 5000);
});
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
To run this, save this code in a HTML file on your desktop. Then create a file called test.txt, write something in it and save it.
Next, open the HTML document in (for example) Firefox. Don't use chrome when testing locally as it will block the XMLHttpRequest owing to its same origin policy.
Make sure the text file has loaded into the HTML document as it should, then alter the text file in some way and save it again.
You should see the changes appear in your web page within five seconds.
I'm not sure if this is the best way to approach things.
Would be glad to hear of any other approaches.
Bookmarks