Open an output stream, add some text, then close the output stream:
More "Try it Yourself" examples below.
The open() method opens an output stream to collect the output from any document.write() or document.writeln() methods.
Once all the writes are performed, the document.close() method causes any output written to the output stream to be displayed.
Note: If a document already exists in the target, it will be cleared.
Note: Do not confuse this method with the window.open() method, which opens a new browser window.
Method | |||||
---|---|---|---|---|---|
open() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
MIMEtype | Optional. The type of document you are writing to. Default value is "text/html" |
replace | Optional. If set, the history entry for the new document inherits the history entry from the document which opened this document |
Return Value: | No return value |
---|
Using parameters; Open an output stream, add some text, then close the output stream:
Using window.open() together with document.open() to open an output stream in a new window, add some text, then close the output stream: