Open In App

HTML DOM open() Method

The DOM Open() method in HTML is the combination of the following three steps:

Syntax:



document.open( MIMEtype, replace )

Parameter Values: This method accepts two parameters which are listed below:

Example 1: In this example, we will use  DOM Open() method






<!DOCTYPE html>
<html>
<head>
    <title>DOM open() Method</title>
</head>
<body>
    <p>GeeksforGeeks</p>
    <button onclick="Geeks()">
        Click Here!
    </button>
    <script>
        function Geeks() {
            /* DOM open() method used here */
            document.open("text/html", "replace");
            document.write("Welcome to GeeksforGeeks");
            document.close();    
        }
    </script>
</body>
</html>

Output:

 

Example 2: This example displays the output in a new window. 




<!DOCTYPE html>
<html>
<head>
    <title>DOM open() Method</title>
</head>
<body>
    <p>GeeksforGeeks</p>
    <button onclick="Geeks()">
        Click Here!
    </button>
    <script>
        function Geeks() {
            let x = window.open();
            /* DOM open() method used here */
            x.document.open("text/html", "replace");
            x.document.write("Welcome to GeeksforGeeks");
            x.document.close();
        }
    </script>
</body>
</html>

Output:

 

Supported Browsers: The browser supported by the DOM open() method is listed below:


Article Tags :