X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM open() Method

Document Object Reference Document Object

Definition and Usage

The open() method opens an output stream to collect the output from any document.write() or document.writeln() methods.

Once all the writes are performed, the document.close() method causes any output written to the output stream to be displayed.

Note: If a document already exists in the target, it will be cleared. If this method has no arguments, a new window (about:blank) is displayed.

Syntax

document.open(MIMEtype,replace)

Parameter Description
MIMEtype Optional. The type of document you are writing to. Default value is "text/html"
replace Optional. If set, the history entry for the new document inherits the history entry from the document which opened this document


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The open() method is supported in all major browsers.


Example

Example

Open an output stream, add some text, then close the output stream:

document.open("text/html","replace");
document.write("<h2>Learning about the HTML DOM is fun!</h2>");
document.close();

Try it yourself »

Example 2

Open an output stream (in a new window; about:blank), add some text, then close the output stream:

<html>
<body>

<script>
var w=window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
</script>

</body>
</html>

Try it yourself »


Document Object Reference Document Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook