You are here: Reference > JavaScript > client-side > HTML DOM > properties > name (frame, iframe)

name property (frame, iframe)

Browser support:
Sets or retrieves the initial name of the contained window.
The name of a window can be used to identify the window. If the target property of an anchor is set to the name of a window, then clicking on the anchor opens the referred page in the window.
Note: in JavaScript, the name of a window can be modified after the window is created. When a window is opened in a frame, modifying the value of the frame's name property has no effect on the name of the contained window and modifying the name of the contained window has no effect on the value of the frame's name property. See Example 2 for details.
If you need detailed information about named windows, please see the page for the name (window) property.
The name property can be used as a reference on the client side. You can get an array of elements that have the same name with the getElementsByName method.

Syntax:

object.name;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: name

Possible values:

String that sets or retrieves the initial name of the contained window.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the name attribute:
Code
frame.htm
<a id="myAnchor" href="frame.htm" target="TargetFrame">Click on it!</a>
<iframe name="TargetFrame" src="" height="150px" width="200px"></iframe>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the name property for windows:
Code
frame.htm
<head>
    <script type="text/javascript">
        function ModifyNames () {
            var frame = document.getElementsByName ("TargetFrame")[0];

            alert ("The name of the frame: " + frame.name);
            alert ("The name of the window: " + frame.contentWindow.name);

            frame.name = "myFrame";
            alert ("The name of the frame: " + frame.name);
            alert ("The name of the window: " + frame.contentWindow.name);

            frame.contentWindow.name = "myWindow";
            alert ("The name of the frame: " + frame.name);
            alert ("The name of the window: " + frame.contentWindow.name);
        }
    </script>
</head>
<body>
    <iframe name="TargetFrame" src="frame.htm" height="150px" width="200px"></iframe>

    <button onclick="ModifyNames ();">Change the name of the frame and the contained window!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content