You are here: Reference > JavaScript > client-side > dialog > methods > close (document)

close method (document)

Browser support:
Closes the output stream opened by the write method and flushes the output buffer to the screen.
The open method opens the output stream for writing. When the document stream is opened, the write and writeln methods can be used to write some content into the document. If the document was opened by the open method, the close method must be used to close the output stream.
Note: while the document is loading, the document stream is opened for writing. In that case, there is no need to open and close the output stream. After the document is loaded, the open method (if at most two parameters are specified) clears the current document.

Syntax:

object.close ( );
You can find the related objects in the Supported by objects section below.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the open, write and close methods to replace the contents of the document:
<head>
    <script type="text/javascript">
        function ReplaceContent () {
            document.open ("text/html");
            document.write ("<b>Bold text</b>");
            document.write ("<i>Italic text</i>");
            document.close ();
        }
    </script>
</head>
<body>
    <button onclick="ReplaceContent ();">Replace the contents of the document</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content