YouTip LogoYouTip

Met Doc Open

# HTML DOM open() Method [![Image 8: Document Object Reference Manual](#) Document Object](#) * * * ## Definition and Usage The open() method opens an output stream to collect the output from the [document.write()](#) or [document.writeln()](#) methods. After calling the open() method to open a new document and setting the document content with the write() method, you must remember to close the document with the [document.close()](#) method and force its content to display. **Note:** If the target file already exists, it will be cleared. If this method has no parameters, a new window (about:blank) will be displayed. ## Syntax document.open(_MIMEtype_,replace) | Parameter | Description | | :--- | :--- | | MIMEtype | Optional. Specifies the type of the document being written. The default value is "text/html". | | replace | Optional. When this parameter is set, it can cause the new document to inherit the history entry from the parent document. | * * * ## Browser Support ![Image 9: Internet Explorer](#)![Image 10: Firefox](#)![Image 11: Opera](#)![Image 12: Google Chrome](#)![Image 13: Safari](#) The open() method is supported by all major browsers. * * * ## Example ## Example Open an output stream and add text, then close the output stream: function createDoc(){ var doc=document.open("text/html","replace"); var txt="Learning HTML DOM is fun!"; doc.write(txt); doc.close(); } [Try it yourself Β»](#) ## Example 2 Open an output stream (a new window; about:blank), add text, then close the output stream: var w=window.open(); w.document.open(); w.document.write("

Hello World!

"); w.document.close(); [Try it yourself Β»](#) * * Document Object](#)
← Prop Doc ReadystateMet Document Createcomment β†’