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

defaultView property (document, XMLDocument)

Browser support:
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.


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:
    <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);
    <iframe src="frame1.htm"></iframe>
    <iframe src="frame2.htm"></iframe>
    <br /><br />
    <button onclick="GetLocations ();">Get the location of the frames</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content