HTML DOM open() Method

## JavaScript Reference

Overview

## JavaScript Objects

JS Array JS Boolean JS Date JS Math JS Number JS String JS RegExp JS Global

## Browser Objects

Window Navigator Screen History Location

## HTML DOM Objects

DOM Document DOM Elements DOM Attributes DOM Events

## HTML Objects

DOM Anchor DOM Area DOM Base DOM Body DOM Button DOM Form DOM Frame/IFrame DOM Frameset DOM Image DOM Input Button DOM Input Checkbox DOM Input File DOM Input Hidden DOM Input Password DOM Input Radio DOM Input Reset DOM Input Submit DOM Input Text DOM Link DOM Meta DOM Object DOM Option DOM Select DOM Style DOM Table DOM td / th DOM tr DOM Textarea

# HTML DOM open() Method

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

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

## Example

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

<html>
<head>
<script>
function createDoc()
{
var doc=document.open("text/html","replace");
var txt="<html><body>Learning about the HTML DOM is fun!</body></html>";
doc.write(txt);
doc.close();
}
</script>
</head>
<body>
<input type="button" value="New document" onclick="createDoc()">
</body>
</html>
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

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE