HTML DOM Document open() method
- Previous page normalizeDocument()
- Next page querySelector()
- Go back to the previous level HTML DOM Documents
Definition and usage
open()
This method opens a document for writing.
Note:All existing document content will be cleared.
Tip:Do not confuse this method with opening a new browser window by window.open() method Confusion.
See also:
Example
Example 1
Open this document, write some text, and then close:
document.open(); document.write("<h1>Hello World</h1>"); document.close();
Example 2
Use 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();
Example 3
If document.write() is used on a closed document, document.open() will be called automatically. This will delete the existing content.
document.write("<h1>Hello World!</h1>");
Syntax
document.open()
document.open(Mimetype, replace)
Parameter
Parameter | Description |
---|---|
Mimetype | Ignored by all modern browsers. |
replace | Ignored by all modern browsers. |
Return value
None.
Browser support
document.Open()
It is a DOM Level 1 (1998) feature.
All browsers support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous page normalizeDocument()
- Next page querySelector()
- Go back to the previous level HTML DOM Documents