You are here: Reference > JavaScript > client-side > HTML DOM > properties > parentWindow (document)

parentWindow property (document)

Browser support:
Returns a reference to the window object that contains the current document.
The parentWindow property is only supported in Internet Explorer. In other browsers, use the defaultView property for similar functionality.

Syntax:

object.parentWindow;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Reference to the parent window object.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the parentWindow property:
Code
frame1.htm
frame2.htm
<head>
    <script type="text/javascript">
        function GetLocationFromDocument (doc) {
            var parWindow = doc.defaultView ? doc.defaultView : doc.parentWindow;
            alert (parWindow.location.href);
        }

        function GetLocations () {
            var frameTags = document.getElementsByTagName ("iframe");
            for (var i = 0; i < frameTags.length; i++) {
                var frameTag = frameTags[i];

                var frameDoc = frameTag.contentDocument ? frameTag.contentDocument : frameTag.contentWindow.document;

                GetLocationFromDocument (frameDoc);
            }
        }
    </script>
</head>
<body>
    <iframe src="frame1.htm"></iframe>
    <iframe src="frame2.htm"></iframe>
    
    <br /><br />
    <button onclick="GetLocations ();">Get the location of the frames</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content