document.open() opens a document for writing with document.write(). It clears the document: existing nodes are removed, and event listeners on the document, its nodes, and its window are dropped (MDN). Always finish with document.close().
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.open. Start with this line.
JavaScript
document.open()
Call
What it does
document.open()
Primary signature.
document.open(...)
Call with the arguments your case needs.
Built into the browser. Call open(...) on document — no import required.
Library declarations
JavaScript
document.open()
Parameters
This member has no parameters beyond those shown in the signature.
Clear with DOM.replaceChildren() empties a host without opening a stream.
Create a node.createElement("p") builds structured content.
Append. No parser quirks from string HTML injection.
Why prefer this. MDN steers new projects to modern DOM over open/write.
Compatibility
Browser Support
Document.open() is widely implemented but marked Deprecated on MDN. Avoid it in new projects even though engines still ship it. See the MDN open() reference.
✓ Deprecated · Widely implemented
Document.open()
Still present in major browsers for legacy dynamic markup insertion. Prefer modern DOM APIs for new code.
LegacyDeprecated API
Google ChromeAll modern versions
Yes
Microsoft EdgeAll modern versions
Yes
Mozilla FirefoxAll modern versions
Yes
Apple SafariAll modern versions
Yes
OperaAll modern versions
Yes
Internet ExplorerSupported (legacy)
Yes
open()Avoid in new apps
Bottom line: Supported for literacy and legacy pages. For new work, use createElement, append, and replaceChildren instead of open/write/close.
Frequently Asked Questions
It opens a document for writing. Side effects include removing all event listeners on the document, its nodes, and its window, and removing all existing nodes from the document (MDN).
Yes. MDN marks Document.open() as Deprecated. Avoid it in new projects; the dynamic markup insertion API (including document.write()) has idiosyncratic behavior and may be removed from standards or browsers. Prefer modern DOM APIs.
A Document object instance (MDN) — typically the same document you called open() on.
MDN Notes: an automatic document.open() call happens when document.write() is called after the page has loaded.
Yes. The three-argument form document.open(url, name, features) is an alias of Window.open() (MDN). Example: document.open("https://www.github.com", "", "noopener=true").
document.open(type, replace) is obsolete. It no longer throws; it forwards to document.open() with no arguments. History replacement now always happens (MDN).