Availability
JavaScript 1.0
Synopsis
document.write(value, ...)Arguments
value
An arbitrary JavaScript value to be
appended to document. If the value is not
a string, it is converted to one before being appended.
...
Any number (zero or higher) of additional values to be appended (in
order) to document.
Description
document.write( )
appends each of its arguments, in order, to
document. Any arguments that are not
strings are converted to strings before they are written to the end
of the document.
Document.write( ) is usually 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 the contents of a document for a window other
than the current window. In this case, the target document is never
in the process of being parsed, and so the output cannot appear
"in place" as it does in the case just described. In
order for write( ) to output text into a document,
that document must be open. You can open a document by explicitly
calling the Document.open( ) method. In most cases
this is unnecessary, however, because when write(
) is invoked on a document that is closed, it implicitly
opens the document. When a document is opened, any contents that
previously appeared in that document are discarded and replaced with
a blank document.
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 should be closed by calling Document.close(
). Note that although the call to open(
) is usually optional, the call to close(
) is never optional.
The results of calling Document.write( ) may not
be immediately visible in the targeted web browser window or frame.
This is because a web browser may buffer up data to output in larger
chunks. Calling Document.close( ) is the only way
to explicitly force all buffered output to be "flushed"
and displayed in the browser window.
See Also
Document.close( ), Document.open( ), Document.writeln( ); Chapter 14