View Full Version : can I rewrite the contents of a frame without reloading the frame

10-20-2003, 09:31 AM

I am working on a web-based IM app. Currently It is running in a pop-up window which is divided into three horizontal frames (header, main message display area, and message input area).

It is all working OK, but I am currently refreshing the display frame every 2 seconds so that it will display any new messages that have been sent (using PHP and MySQL for backend stuff). The problem is that with IE it makes a horrible clicking sound on each refresh and the hourglass icon briefly flashes on the screen.

These are not affecting the app as such but it would be nice if I could do it another way so that this did not occur...is it possible? I have been told that with javascript I may be able to get the new page contents without actually doing a refresh/reload of the frame.

Any suggestions welcome.



Roy Sinclair
10-20-2003, 03:46 PM
You're asking about an elemental Javascript capability:

document.frames["name of the frame"].document.open();
document.frames["name of the frame"].document.write("content here, multiple write statements are ok");
document.frames["name of the frame"].document.close(); // This line is where the new contents should be complete and ready for the user

10-21-2003, 03:33 AM
hmm... not really what I want I think.

I might be wrong but it seems that this sort of thing can only update frames that are within the the same users client. I need the browser to fetch new data from a database every 2 secs or so and display it in the frame for every user that is logged on. So if user 'a' types in 'hello' it will apear in all other user's display frames (within 2 secs or whatever refresh rate is).

The best I could get it to do with a variation* on your js code was to update the messages in the users browser only when they sent a message (ie their own message would appear in the display along with any other messages that were sent by others users since this users last post, BUT other users displays are not updated until they send a message, obviously)

The reason for this is that on sending their message a php script is run that reloads the necessary frames with the new data. But I cannot get new external data into the document.write() call without reloading the page through the php script.

Is there some way I can load a (php generated) page into the frame with the document.open() call (as for window.open()) or otherwise?

Thanks for your suggestion anyhow.


* I had to use the following code to get any kind of functionality:

type='text/css' href='css/helpLine.css'><div class=\"chat-box\">
<?echo $messages; ?></div>");

10-21-2003, 11:07 AM

function getMessages(){
var xmlhttp;
var responseText = '';
if (ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("GET", "http://mydomain.com/messages.php", false);
if (xmlhttp.status==200){
parent.window.frames[2].document.getElementById('chat-box').innerHTML = xmlhttp.responseText;

call that function every 2 secs. I recommend using a longer delay coz as the messages get longer, the response of the server would be slower.
It can also be made to work with Mozilla and NS7. Just google it.

10-21-2003, 11:16 AM
try using

document.getElementById(id).innerHTML = "new content text here...";

instead of document.write

and see that there must be an ActiveX method of refreshing a server-side application

10-21-2003, 11:18 AM
oops :-) I see that glenngv already gave you the same but a more compresesive advice.

10-21-2003, 02:37 PM
Thanks glenngv, I'll give it a go tomorrow (gettin' late here in Aus). The php script only ever sends the last 20 messages to be displayed so the reload time is usually ok. I don't really know much about ActiveX stuff(not being much of a MS man), looks like I need to do some nore reading ;-).

And yeah even though IE has the major market share I still want it to work properly on Mozilla, cause its what I use and I hate it when I get IE only coded pages ;-)

cheers, chameleon

10-22-2003, 06:20 AM
As I said in my previous post, you can use XMLHTTP in Mozilla. I googled (http://jibbering.com/2002/4/httprequest.html) it for you.

10-22-2003, 07:07 AM

10-22-2003, 09:53 AM
thanks all,

I'll post back once I've had a chance to rewrite the necessary parts and get it all working.



10-27-2003, 12:57 AM
great, I've got it working nicely on Mozilla and IE, thanx everyone for your help.