HTML | DOM Window opener Properties (original) (raw)

Last Updated : 10 Sep, 2024

The **Window opener property in HTML DOM is used to return the reference of newly created windows. This property is used to return the details of the source (parent) window. A window is opened using the window.open() method and closed using the window.opener.close() method.

**Syntax:

window.opener

**Return Value:

It returns the reference of the created window.

**Example 1: This example shows the single window opening on clicking the button.

HTML `

HTML DOM Window opener Property
<h2>
    HTML DOM Window opener Property
</h2>

<button onclick="myGeeks()">
    Click Here!
</button>

<!-- script to open new windows -->
<script>
    function myGeeks() {
        let win = window.open("", "win",
            "width = 500, height = 300");

        win.document.write("<p>New Window</p>");

        win.opener.document.write("<p>Parent Window</p>");
    }
</script>

`

**Output:

**Example 2: This Example shows the double window creation on clicking the single button.

HTML `

HTML DOM Window opener Property
<h2>
    HTML DOM Window opener Property
</h2>

<button onclick="myGeeks()">
    Click Here!
</button>

<!-- script to create two window -->
<script>
    function myGeeks() {
        let win1 = window.open("", "win1",
            "width = 500, height = 300");

        let win2 = window.open("", "win2",
            "width = 400, height = 250");

        win1.document.write("<p>New Window 1</p>");
        win2.document.write("<p>New Window 2</p>");

        win1.opener.document.write("<p>Parent Window</p>");
        win2.opener.document.write("<p>Parent Window</p>");
    }
</script>

`

**Output:

**Supported Browsers