Section 25.154. HTMLDocument.write( ): append HTML text to an open document


25.154. HTMLDocument.write( ): append HTML text to an open document

DOM Level 0

25.154.1. Synopsis

 void write(String text); 

25.154.1.1. Arguments

text

The HTML text to be appended to the document.

25.154.2. Description

This method appends the specified HTML text to the document. According to the DOM standard, this method takes a single string argument. According to common practice, however, the write( ) method may be passed any number of arguments. These arguments are converted to strings and appended, in order, to the document.

Document.write( ) is normally used in one of two ways. First, it can be invoked on the current document within a <script> tag or within a function that is executed while the document is being parsed. In this case, the write( ) method writes its HTML output as if that output appeared literally in the file at the location of the code that invoked the method.

Second, you can use Document.write( ) to dynamically generate new documents in a window, frame, or iframe other than the one in which the calling script is running. If the target document is open, write( ) appends to that document. If the document is not open, write( ) discards the existing document and opens a new (empty) one to which it appends its arguments.

Once a document is open, Document.write( ) can append any amount of output to the end of the document. When a new document has been completely generated by this technique, the document must be closed by calling Document.close( ). Note that although the call to open( ) is optional, the call to close( ) is never optional.

The results of calling Document.write( ) may not be immediately visible in the target document. This is because a web browser may buffer up text to parse and display in larger chunks. Calling Document.close( ) is the only way to explicitly force all buffered output to be "flushed" and displayed.

25.154.3. See Also

HTMLDocument.close( ), HTMLDocument.open( )




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net