HTML DOM Document open()
Example
Open this document, write some text, and close:
document.open();
document.write("<h1>Hello World</h1>");
document.close();
Try it Yourself »
Using document.open() in a new window:
const myWindow = window.open();
const myWindow.document.open();
const myWindow.document.write("<h1>Hello World!</h1>");
const myWindow.document.close();
Try it Yourself »
More examples below.
Definition and Usage
The open()
method opens a document for writing.
Warning!
All existing document content will be cleared.
Note
Do not confuse this method with the window.open() method, which opens a new browser window.
See Also:
Syntax
document.open()
document.open(Mimetype, replace)
Parameters
Parameter | Description |
Mimetype | Ignored by all modern browsers. |
replace | Ignored by all modern browsers. |
Return Value
NONE |
More Examples
If document.write() is used on a closed document, document.open() is automatically called. This will delete existing content.
document.write("<h1>Hello World!</h1>");
Try it Yourself »
Browser Support
document.Open()
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |