HTML | DOM Window opener Properties

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 created window.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        HTML DOM Window opener Property
    </title>
</head>
  
<body>
      
    <h2>
        HTML DOM Window opener Property
    </h2>
      
    <button onclick = "myGeeks()">
        Click Here!
    </button>
  
    <!-- script to open new windows -->
    <script>
        function myGeeks() {
            var win = window.open("", "win",
                        "width = 500, height = 300");
                          
            win.document.write("<p>New Window</p>");
              
            win.opener.document.write("<p>Parent Window</p>");
        }
    </script>
</body>
  
</html>                                    

chevron_right


Output:
Before click on the button:

After click on the button:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>
        HTML DOM Window opener Property
    </title>
</head>
  
<body>
      
    <h2>
        HTML DOM Window opener Property
    </h2>
      
    <button onclick = "myGeeks()">
        Click Here!
    </button>
      
    <!-- script to create two window -->
    <script>
        function myGeeks() {
            var win1 = window.open("", "win1", 
                    "width = 500, height = 300");
                      
            var 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>
</body>
  
</html>                    

chevron_right


Output:
Before click on the button:

After click on the button:

Supported Browsers: The browser supported by DOM Window opener property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.