You are here: Reference > JavaScript > client-side > HTML DOM > properties > target (a, area, base, form, link)

target property (a, area, base, form, link)

Browser support:
Specifies or returns the target window or frame where the document is to be opened.

Syntax:

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

Possible values:

String that identifies the target window.
One of the following values:
_blank
Indicates a new window.
_media
Indicates the HTML content area of the Media Bar.
_parent
Indicates the parent frame.
_search
Indicates the browser search panel.
_self
Default. Indicates the frame containing the source link.
_top
Indicates the topmost window.
Target name
The name of the target window or frame (frame or iframe). If there is no window or frame with the specified name opened for the current document, a new window will be opened, otherwise the target references the matching window. If a new window is opened, the name property of the window will contain the value specified by the target property.
Default: _self.

Example HTML code 1:

This example illustrates the use of the target 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 target property:
Code
frame.htm
<head>
    <script type="text/javascript">
        function GetAnchorTarget () {
            var anchor = document.getElementById ("myAnchor");
            alert (anchor.target);
        }
    </script>
</head>
<body>
    <a id="myAnchor" href="frame.htm" target="TargetFrame">Click it!</a>

    <br />
    The target of the link is the next iframe
    <br />

    <iframe name="TargetFrame" src="" height="150px" width="200px"></iframe>

    <button onclick="GetAnchorTarget ();">Get the target of the anchor!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content