
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM close() method
The HTML DOM close() method is used to close the output stream. It is done to indicate that writing on the window has been finished. It doesn’t take any parameter and displays all the previous data before closing.
Syntax
Following is the syntax for HTML DOM close() method −
document.close()
Example
Let us see an example for the close() method −
<!DOCTYPE html> <html> <body> <p>Click the below button to open an output stream put some text in it and finally close it.</p> <button onclick="streamClose()">CLOSE STREAM</button> <script> function streamClose() { document.open(); document.write("<h1>SAMPLE HEADING</h1>"); document.write("<h2>SAMPLE HEADING 2</h2>"); document.write("<p>A paragraph</p>"); document.close(); } </script> </body> </html>
Output
This will produce the following output −
On clicking CLOSE STREAM −
We have created a button CLOSE STREAM that will execute the streamclose() method on click −
<button onclick="streamClose()">CLOSE STREAM</button>
The streamClose() method uses the open method on document which opens a new stream and clears all the previous text that was written on the document. Using document.write we write a <h1> , <h2> and <p> element to the document. Finally, we close that input stream using the close() method on the document.−
function streamClose() { document.open(); document.write("<h1>SAMPLE HEADING</h1>"); document.write("<h2>SAMPLE HEADING 2</h2>"); document.write("<p>A paragraph</p>"); document.close(); }
- Related Articles
- HTML DOM addEventListener() Method
- HTML DOM normalize( ) Method
- HTML DOM write() Method
- HTML DOM writeln() Method
- HTML DOM insertAdjacentElement( ) Method
- HTML DOM insertAdjacentHTML( ) Method
- HTML DOM insertAdjacentText( ) Method
- HTML DOM insertBefore( ) Method
- HTML DOM isDefaultNamespace( ) Method
- HTML DOM isEqualNode( ) Method
- HTML DOM isSameNode( ) Method
- HTML DOM item( ) Method
- HTML DOM appendChild() Method
- HTML DOM blur() Method
- HTML DOM click() method
