Pre-Defined Window Targets
Most likely, you're already familiar with the target="_blank" attribute you can put into an "a" tag so the link opens a new window. (Your browser might open a new tab instead of a new window.)
Example:
<a target="_blank" href="http://example.com">Click</a>
The value "_blank" is a pre-defined target value. There are other pre-defined target values that can be used in "a" tag links. No JavaScript required. No PHP required. No other software required. Just HTML.
There are four pre-defined target attribute values:
Pre-defined Value | Description |
---|---|
_self | Load the page in the window, tab, or iframe where the link was clicked. |
_blank | Load the page in a new window or tab. |
_parent | Load the page in the parent window, tab, or iframe. |
_top | Load the page in the top window or tab. |
Below is more information about each of the pre-defined target attribute values. (The phrase "opens the page" means "opens the page that was linked to in the 'a' tag's href attribute." And "link" means "'a' tag link.")
-
_self
When the link is clicked, the browser opens the page in the same window, tab, or iframe where the link is located.
The target="_self" value is the default target value. Links open in the current window or tab unless the browser is told to do otherwise by a specific target attribute or JavaScript.
-
_blank
When the link is clicked, the browser opens the page in a new window or tab.
Generally, target="_blank" is implemented to open a new window or tab so the site visitor will return to the page the link is on when the new window or tab is closed.
-
_parent
When the link is clicked, the browser opens the page in the parent window, tab, or iframe.
A parent window is a window with an iframe or that spawned another window. When the link in the iframe or other window is clicked, target="_parent" causes the page to open in the parent window. If the window has no parent, then _parent defaults to _self.
-
_top
When the link is clicked, the browser opens the page in the top window or tab.
If a window contains an iframe or spawns another window, then the top window is the one with the iframe or that spawned another window (At this point, "_top" and "_parent" mean the same thing).
Now, if that iframe or spawned window itself contains an iframe or spawns its own window, the top window is the window that contains the first iframe or spawned the first window in the chain. No matter how many iframes or spawned windows contain more iframes or spawned windows, the top window is the first window in the chain.
If the window with a target="_top" link is not in an iframe and isn't a spawned window, then _top defaults to _self.
The target attribute may contain values other than the pre-defined ones. The iframe or other window with a name="..." attribute value that matches the link's target="..." value is where the page opens.
As an example, click this link to load an image of the Black Canyon of the Gunnison, South Dakota, USA into the iframe below.
Here's the source code to reproduce the example:
<a target="example_URL" href="//www.willmaster.com/library/external/ToPullIntoIframe.php"> click this link </a> <iframe name="example_URL" src="//www.willmaster.com/library/external/ToPreloadTheIframe.php"; style="width:277px; height:362px; overflow:none; border:1px solid black; border-radius:9px; box-sizing:border-box; padding:none; background-color:#efefef;" scrolling="no"> </iframe>
The target attribute in the link has a value "example_URL" and the name attribute of the iframe tag has a value of "example_URL" (both colored blue). Therefore, when the link is clicked, it affects the iframe.
When a target attribute contains a value that doesn't match the name attribute value of an iframe or another window, and it isn't a pre-defined value, then the target attribute value defaults to _blank.
(This article first appeared in Possibilities ezine.)
Will Bontrager