English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM open() method

HTML DOM Document Object

open()The method opens an output stream to collect any output that isdocument.write()ordocument.writeln()the output of the method.

You can usedocument.close()Close the opened document.

If a document already exists in the target, clear it.

Do not use this method withwindow.open()Method obfuscation:

  • document.open() allows you to overwrite the current document or append to the current document

  • The window.open() method provides a way to open a new window while keeping the current document unchanged

Syntax:

document.open(MIMEtype, replace)
document.open();
document.write("<p>Unique Content.</p>
document.close();
Test See </›

Browser compatibility

All browsers fully support the open() method:

Method
open()YesYesYesYesYes

Parameter value

ParameterDescription
MIMEtype(Optional) The document type you want to write (default is "text", / html
replace(Optional) If set, the new document's history entry will inherit the history entry of the document opened by the document

Technical details

Return value:None
DOM Version:DOM 2Level

More Examples

Using Parameters: Open the output stream, add some text, and then close the stream:

document.open("text/html
document.write("<p>Unique Content.</p>
document.close();
Test See </›

Use window.open() and document.open() to open a stream in a new window, add some text, and then close the stream:

var w = window.open();
w.document.open();
w.document.write("<h1>Unique Content</h1">);
w.document.close();
Test See </›

Related References

DOM Document write()Methods

DOM Document writeln()Methods

DOM Document close()Methods

window open()Methods

HTML DOM Document Object