Name
HTMLDocument.write( ): append HTML text to an open document â DOM Level 0
Synopsis
void write(Stringtext
);
Arguments
-
text
The HTML text to be appended to the document.
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 ...
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.