HTML DOM open() method
Document Object
Definition and Usage
The open() method opens an output stream to collect document.write() or document.writeln() the content output by the method.
After calling the open() method to open a new document and using the write() method to set the document content, you must remember to use document.close() method to close the document and force its content to be displayed.
**Note:** If the target file already exists, it will be cleared. If this method is called without parameters, a new window (about:blank) will be displayed.
Syntax
document.open(
MIMEtype
,replace)
| Parameters | Description |
|---|---|
| MIMEtype | Optional. Specifies the type of document being written. The default value is "text/html". |
| replace | Optional. When this parameter is set, it causes the new document to inherit the history entries from the parent document. |
Browser support





All major browsers support the open() method.
Example
Example
Open an output stream, add text, then close the output stream:
Try it »
Example 2
Open an output stream (a new window; about:blank), add text, then close the output stream:
Try it »
Document Object