How can a script in one frame write text into another frame?To write text from one frame to another, you must be able to access the document object associated with the destination frame. This object contains several methods that can be used to write dynamic text into the destination frame without explicitly loading a new document.
documentobject has four methods that are useful for dynamically writing text to a document.
document . open ()
openmethod erases the current document so that the next
writestatement can start with a "clean slate." With no parameters, the
openmethod defaults to MIME-type "html/text," which means that subsequent write statements should send HTML-formatted text to the document.
document . write ()
document . writeln ()
writelnmethods output text to the document. The only difference between these two methods is that
writelnoutputs a newline character after the text. In most cases, however, it doesn't matter which one you use, since newline characters are significant only in certain contexts (such as preformatted text).
document . close ()
<br>tag, or some other line-ending element. However, if a script is finished writing to the document, then it should just call the
closemethod, which signals the end of the line and the document.
writelnmethods are called but the document is not yet open, the
openmethod will automatically be called (and the current document cleared).
openmethod is called but the document is already open, the
closemethod will be called before the document is re-opened.
documentobject as a property of its window object. Thus, any frame can output text to another frame simply by calling methods in the destination frame's
For example, consider the following
frameset code, which divides the browser window into two, side-by-side frames:
A script in a.html (left frame) that outputs text in the right frame might appear as follows:
In this example,
top . right . document . open (); top . right . document . writeln ("Hello."); top . right . document . close ();
topis a window reference to the whole window, and
top.rightis a window reference to the right frame. When this script is executed, the content from b.html is replaced by the new text: "Hello."
This article provides only a brief overview of how one frame can write to another. If you plan on writing serious web applications that use this feature, you should study Netscape's documentation for the
22 February 1996