You are here: Reference > JavaScript > client-side > HTML DOM > objects > frames

frames collection

Browser support:
Represents a collection of all window objects that belong to frame and iframe elements in the current document.
The elements in the collection are sorted in source code order.

Syntax:

Properties that reference the object:
object.frames
Related objects:

Possible members:

Properties:
length
Returns an integer that specifies the number of objects in the current collection.

This property is read-only.
Methods:
[nameOrIndex]
Returns an object from the current collection by name or index.

Parameters:

nameOrIndex
Required. String or zero-based integer that specifies the object to retrieve.
  • If an integer value is specified, it specifies the index of the object to retrieve.
  • If this parameter is a string, then it specifies a value for the name or id property of the object to retrieve.

Return value:

If no match is found, it returns undefined. If exactly one match is found, it returns the matching window object. If more than one match is found, it returns the first matching window object.
item (nameOrIndex)
Returns an object from the current collection by name or index.

Parameters:

nameOrIndex
Required. String or zero-based integer that specifies the object to retrieve.
  • If an integer value is specified, it specifies the index of the object to retrieve.
  • If this parameter is a string, then it specifies a value for the name or id property of the object to retrieve.

Return value:

If no match is found, it returns null. If exactly one match is found, it returns the matching window object. If more than one match is found, raises an exception.

Example HTML code 1:

This example illustrates the use of the frames collection:
Code
editable.htm
<head>
    <script type="text/javascript">
        var editorDoc;
        function InitEditable () {
            var editorWindow = window.frames["editor"];
            editorDoc = editorWindow.document;          
            var editorBody = editorDoc.body;

                // turn off spellcheck
            if ('spellcheck' in editorBody) {   // Firefox
                editorBody.spellcheck = false;
            }

            if ('contentEditable' in editorBody) {
                    // allow contentEditable
                editorBody.contentEditable = true;
            }
            else {  // Firefox earlier than version 3
                if ('designMode' in editorDoc) {
                        // turn on designMode
                    editorDoc.designMode = "on";                
                }
            }
        }

        function ToggleBold () {
            editorDoc.execCommand ('bold', false, null);
        }
    </script>
</head>
<body onload="InitEditable ();">
    First, write and select some text in the editor.
    <br />
    <iframe name="editor" src="editable.htm"></iframe>
    <br /><br />
    You can toggle the bold/normal state of the selected text with this button:
    <br />
    <button onclick="ToggleBold ();">Bold</button>
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content