You are here: Reference > JavaScript > client-side > HTML DOM > properties > self (window)

self property (window)

Browser support:
Returns a reference to the window object itself.
The use of the self property is optional, the window.self and window forms are equivalent. Sometimes the use of the self property may result in readable code.

Syntax:

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

Possible values:

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

Example HTML code 1:

This example illustrates a case when the use of the self property causes more readable code:
<head>
    <script type="text/javascript">
        function TestTopLevel () {
            if (window.parent == window.self) {
                alert ("The document is a top-level document.");
            }
            else {
                alert ("The document is in a frame.");
            }
        }
    </script> 
</head>
<body>
    With the following button, you can check if the current document is in a frame or it is a top-level document.
    <br />
    <button onclick="TestTopLevel ();">Test top-level</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content