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

defaultView property (document, XMLDocument)

Browser support:
9
Retrieves a reference to the default AbstractView object for the current document.
The returned object is generally the window object that contains the current document.
Note: The defaultView property is supported in Internet Explorer from version 9. In older versions, use the parentWindow property for similar functionality.

Syntax:

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

Possible values:

Reference to the AbstractView object or null.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the defaultView 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