| JavaScript - Dynamically generated documents | | Print | |
Dynamically generated documents
In addition to the properties already described, the Document object defines several important methods for dynamically generating document content. Use the write( ) method to output text into the document at the location of the <script> that contains the method calls. For example:
document.write("<p>Today is: " + new Date());
document.write("<p>Document updated: " +
document.lastModified);
Note that text output in this way may contain arbitrary HTML tags; the browser parses and displays any such text after executing the script that output it.
The write( ) method can be used from a <script> tag only while a document is still loading. If you try to use it within an event handler that is triggered after the document has loaded, it erases the document and the event handler it contains. It is legal, however, to use an event handler in one window or frame to trigger a document.write( ) call into another window. When you do this, however, you must write the complete contents of the new document, and remember to call the document.close( ) method when you are done:
var clock = open("", "", "width=400,height=30");
var d = clock.document; // Save typing below
setInterval("d.write(new Date());d.close();",
1000);
| Users' Comments (0) |
|
No comment posted






