HTML | DOM Window frames Properties

The Window frames property in HTML DOM is used to return the frame element in the form of an array object. This property represents all <iframe> elements in the current window. DOM Windowframe is a read-only property.

Syntax:

window.frames

Return Value: It returns a reference to the Window object, representing all the frames in the current window.

Properties:

  • length property: It returns the number of iframe elements in the current window.
    Syntax:

    window.length

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            HTML | DOM Window frames Property
        </title>
    </head>
      
    <body>
          
        <iframe src = "https://ide.geeksforgeeks.org/tryit.php">
        </iframe><br>
          
        <p>
            Click on the button to display
            the number of iframes
        </p>
          
        <button onclick="myGeeks()">
            Click Here!
        </button>
          
        <p id = "GFG"></p>
          
        <!-- script to count iframes -->
        <script>
            function myGeeks() {
                var x = window.length;
                document.getElementById("GFG").innerHTML = x;
            }
        </script>
    </body>
      
    </html>                    

    chevron_right

    
    

    Output:
    Before click on the button:

    After click on the button:

  • location property: It changes the location of iframe.
    Syntax:

    window.frames[index_no].location

    Example 2:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            HTML DOM Window frames Property
        </title>
    </head>
      
    <body>
          
        <iframe src = "https://ide.geeksforgeeks.org/tryit.php">
        </iframe><br>
          
        <p>
            Click on the button to display
            the number of iframes
        </p>
          
        <button onclick = "myGeeks()">
            Click Here!
        </button>
          
        <p id = "GFG"></p>
          
        <!-- script to count iframes -->
        <script>
            function myGeeks() {
                window.frames[0].location = 
                "https://ide.geeksforgeeks.org/index.php";
            }
        </script>
    </body>
      
    </html>                    

    chevron_right

    
    

    Output:
    Before click on the button:

    After click on the button:

Supported Browsers: The browser supported by DOM Window Frames 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.