HTML - DOM Document close() Method



HTML DOM document close() method is used to close the output stream. It doesnt take any parameter and displays all the previous data before closing.

Syntax

document.close();

Parameter

This method does not accepts any parameter.

Return value

This method does not return anything.

Example of HTML DOM document 'close()' Method

The following example shows the use of document.close() Method as it displays all previous data before closing the document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Document close() Method
    </title>
</head>
<body>
    <button onclick="docClose()">Close</button>
    <script>
        function docClose() {
            document.open();
            document.write("Welcome to Tutorials point <br>");
            document.write("Have a great day");
            document.close();
        }
    </script>
</body>
</html>

Supported Browsers

Method Chrome Edge Firefox Safari Opera
close() Yes 64 Yes 12 Yes 1 Yes 11 Yes 51
html_dom.htm
Advertisements