HTML DOM open() Method
Example
Open an output stream, add some text, then close the output stream:
document.open();
document.write("<h1>Hello World</h1>");
document.close();
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
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.
Browser Support
Method | |||||
---|---|---|---|---|---|
open() | Yes | Yes | Yes | Yes | Yes |
Syntax
document.open(MIMEtype,replace)
Parameter Values
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 |
Technical Details
Return Value: | No return value |
---|
More Examples
Example
Using parameters; Open an output stream, add some text, then close the output stream:
document.open("text/html", "replace");
document.write("<html><body><p>Hello World!</p></body></html>");
document.close();
Try it Yourself »
Example
Using window.open() together with document.open() to open an output stream in a new window, add some text, then close the output stream:
var
w = window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
Try it Yourself »
Document Object