You are here: irt.org | FAQ | JavaScript | History | Q1239 [ previous next ]
The following almost does it:
<script language="JavaScript"><!-- function rewriteOtherFrame(output,frame) { // instead of using document.open() use: parent.frames[frame].document.clear(); // then write output to frame: parent.frames[frame].document.write(output); // instead of using document.close() use: parent.frames[frame].document.write('<br>'); // force output to be displayed } function updateFrame() { // create some changing text var text = '<p>Date/Time: ' + (new Date()) + '<\/p>'; // updates frame 1 rewriteOtherFrame(text,1); // do again in another second setTimeout('updateFrame()',5000); } updateFrame(); //--></script>
However, as document.clear() is deprecated in favour of document.open(), this doesn't work properly in Internet Explorer, as the text is continually added to the end of the last update.
The following uses DHTML to solve the problem for browsers that support DHTML, and document.clear() fro everything else:
frame.htm:
<html> <head> <script language="JavaScript"><!-- var framesetLoaded = false; //--></script> </head> <frameset rows="50%,*" onLoad="framesetLoaded=true"> <frame src="test.htm"> <frame src="blank.htm"> </frameset> </html>
test.htm:
<script language="JavaScript"><!-- function rewriteOtherFrame(output,frame) { if (document.all) { parent.frames[frame].document.all['myid'].innerHTML = output; } else if (document.layers) { parent.frames[frame].document.layers['myid'].document.open(); parent.frames[frame].document.layers['myid'].document.write(output); parent.frames[frame].document.layers['myid'].document.close(); } else { // instead of using document.open() use: parent.frames[frame].document.clear(); // caution: document.clear() is deprecated which // is why we only attempt this on older browsers // then write output to frame: parent.frames[frame].document.write(output); // instead of using document.close() use: parent.frames[frame].document.write('<br>'); // which forces the output to be displayed } } function updateFrame() { // create some changing text var text = '<p>Date/Time: ' + (new Date()) + '<\/p>'; // updates frame 1 if (parent.framesetLoaded) rewriteOtherFrame(text,1); // do again in one second setTimeout('updateFrame()',1000); } updateFrame(); //--></script>
blank.htm:
<div id="myid" style="position:absolute;"></div>