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();
myWindow.document.open();
myWindow.document.write("<h1>Hello World!</h1>");
myWindow.document.close();
Try it Yourself »

More examples below.


Description

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:

The Document close() Method

The Document write() Method

The Document writeln() Method


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 Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.