A question came up on news:comp.lang.tcl about a CGI which gave continuous updates to a Netscape browser. The original question had to do with a problem where Netscape stayed busy even after the CGI was finished (which was about two hours(!) after its started). This evolved into a discussion of how to get page updates that would mimic a real-time monitor without resorting to the use of Java. JavaScript provides a way to modify the contents of a DHTML page, and it occured to me that by sending small JavaScript segments to the browser, it might be possible to have it appear like a real-time monitor that could add or update sections of page rather than simply append to a page. I've written a couple of proof-of-concept pages that do this via PHP[http://www.php.net/], but any CGI-like backend will work. What counts is the contents of the JavaScript and the browser's DOM. You can see the working examples and the PHP code which produced them at http://www.rlenter.com/stuff/server-monitor.html. The critical part seems to be 1. Build your entire page, up to but not including the terminating '''''' tag. 1. Identify the insertion/update point in JavaScript either via a position index (e.g., it's the fourth paragraph) or an '''id=ID-NAME''' tag. 1. Output the JavaScript to insert into/update the page as updates become available. 1. You need to be able to flush output from the server. Browsers may not update the page if they do not receive a full line, so be sure to include a terminating newline in your output. JavaScript Monitor Test

JavaScript Monitor Test

This is a test of a JavaScript Monitor which feeds additional information to the page in "real-time" and eventually finishes the page. This particular "monitor" writes out the page then the replaces a paragraph with updated information using JavaScript. If you look at the page source in your browser, you will see the original HTML source plus all of the JavaScript commands. The "trick" here is that the JavaScript parts which update the page come out slowly. Click here to see the PHP source for this page.

Replace me.


Roland B. Roberts, PhD
RL Enterprises
'; $trailer = ''; echo eval ('?> ' . $header . '' . "\n"; echo ' myP=document.getElementById("x1");' . "\n"; echo ' myTextNode=myP.childNodes[0];' . "\n"; echo '' . "\n"; flush (); for ($i = 1; $i <= 10; $i++) { sleep (2); echo '' . "\n"; flush (); } echo $trailer; ?>