View Full Version : How do I rewrite the contents of one frame from another?

12-31-2005, 11:06 AM
This might be a stupid question, but...

If I have a page split into two frames, how might I rewrite the text in one frame by clicking a link on the other? It looks like this:

var Text = "I am text!"
var Text2 = "I am some different text!"
<a href = "#" onClick = "Top.OtherFrame.document.write(Text);">Link 1</a>
<a href = "#" onClick = "Top.OtherFrame.document.write(Text2);">Link 2</a>

The problem, of course, is that when either link is clinked, it adds text to the text that's already there. I only want the contents of one variable to be visible.

Please help me! It would be much appreciated.

12-31-2005, 05:31 PM
When writing to another frame you need to open and close streaming to the frames document. You do this with document.open() and document.close().

You also need to put you variables between opening and closing <script> tags.

Here's an example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
var Text1 = "I am the text for link 1";
var Text2 = "I am the text for link 2";

<a href="#" onClick="top.frames['otherFrame'].document.open();top.frames['otherFrame'].document.write(Text1);top.frames['otherFrame'].document.close()">Link 1</a><br>
<a href="#" onClick="top.frames['otherFrame'].document.open();top.frames['otherFrame'].document.write(Text2);top.frames['otherFrame'].document.close()">Link 2</a>

Hope that helps

01-02-2006, 03:33 AM
Yes! It works! It finally works! Thank you so much! ^___^

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum