HTML | DOM close() Method
The close() method is used to close the output stream. It is used to indicate finish of writing on a window. The close() method does not require any parameter.
Syntax:
document.close()
Example 1:
<!DOCTYPE html> <html> <head> <title>DOM close Method</title> <style> h1, h2{ color:green; } body { text-align:center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>DOM close() Method</h2> <button onclick="geeks()">Submit</button> <script> // This function is called on submit, it opens // a stream, write "PRACTICE" and then closes // the stream. function geeks() { document.open(); document.write("<h1>PRACTICE</h1>"); document.close(); } </script> </body> </html> |
chevron_right
filter_none
Output:

Example 2: This example use window.close method to show the output in the new window.
<!DOCTYPE html> <html> <head> <style> h1, h2 { color:green; } body { text-align:center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>DOM close() Method</h2> <button onclick="geeks()">Submit</button> <script> // This function is called on submit, it opens // a new window and a stream, write "PRACTICE" and // then closes the stream. function geeks() { var gfg = window.open(); gfg.document.open(); gfg.document.write("<h1>PRACTICE</h1>"); gfg.document.close(); } </script> </body> </html> |
chevron_right
filter_none
Output:

Supported Browsers: The browser supported by DOM close() method are listed below:
- Apple Safari
- Google Chrome
- Firefox
- Opera
- Internet Explorer
Recommended Posts:
- HTML | DOM Dialog close() Method
- PHP | Spreadsheet_Excel_Writer | Close() Function
- Bootstrap | Close Icon for dismissing content with Examples
- How to avoid dropdown menu to close menu items on clicking inside ?
- HTML | DOM contains() Method
- HTML | DOM History go() Method
- HTML | DOM removeAttribute() Method
- HTML | DOM cloneNode() Method
- HTML | DOM isSameNode() Method
- HTML | DOM adoptNode() Method
- jQuery | html() Method
- HTML | DOM click() Method
- HTML | DOM exitFullscreen() Method
- HTML | DOM querySelectorAll() Method
- HTML | DOM setAttributeNode() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



