Target property for HTML <a> tags

Source: Internet
Author: User

Definition and usage

The target property of the <a> tag specifies where to open the linked document.

If a target property is included in a <a> tag, the browser will load and display the document in the frame or window that is named after the href attribute of the tag, which matches the target name. If the frame or window that specifies the name or ID does not exist, the browser opens a new window, gives the window a specified tag, and then loads the new document into that window. From then on, the hyperlinked document can point to this new window.

Open a new window

The hyperlinks that are directed make it easy to create efficient browsing tools. For example, a simple list of content documents can redirect the document to a separate window:

target="view_window" >Preface</a></li>  target="view_window" >chapter 1 </a></li>  target="view_window" >chapter 2</a></li>  target="view_window" >chapter 3</a></li> </ul>

Try it yourself.

When a user selects a link in the table of contents for the first time, the browser opens a new window, marks it as "View_window", and then displays the document content that you want to display. If the user selects another link from this list of contents, and the "View_window" is still open, the browser will then load the selected document into that window again, replacing the documents just now.

Throughout the process, the window containing the table of contents is accessible to the user. You can change the contents of another window by clicking one of the connections in the window.

Open a window in the frame

Instead of opening a full browser window, using target is a more common way to direct hyperlink content to one or more frames in a <frameset> display. You can put this table of contents in one of the frames of a document with two frames and use the adjacent frame to display the selected document:

<frameset cols= "100,*" >  <frame src= "toc.html" >  

Try it yourself.

When the browser initially displays both frames, the left frame contains a table of contents, and the frame on the right contains the preface.

This is the source code for "toc.html":

target="view_frame" >Preface</a></li>  target="view_frame" >chapter 1 </a></li>  target="view_frame" >chapter 2</a></li>  target="view_frame" >chapter 3</a></li> </ul>

Note that in the document "Toc.html", the target of each link is "View_frame", which is the frame on the right.

When a user selects a link from a directory in the left frame, the browser loads the associated document and displays it in the "View_frame" frame on the right. When other links are selected, the contents of the frame on the right are also changed, and the left frame remains unchanged.

Special goals.

There are 4 reserved target names to use for special document redirection operations:

_blank

The browser always loads the target document in a newly opened, unnamed window.

_self

The value of this target is the default target for all <a> tags that do not have a target specified, which causes the target document to be loaded and displayed in the same frame or window as the source document. This goal is superfluous and unnecessary unless used with the target property in the document title <base> tag.

_parent

This goal causes the document to be loaded into the parent window or the frameset that contains the frame referenced by the hyperlink. If the reference is in a window or in a top-level frame, then it is equivalent to the target _self.

_top

This goal causes the document to be loaded into the window containing the hyperlink, with the _top target clearing all the contained frames and loading the document into the entire browser window.

Tip: All 4 values of these target begin with an underscore. Any other window or target that starts with an underscore will be ignored by the browser, so do not underline the first character of any frame name or ID defined in the document.

Grammar
<a target= "value">
Property value
value Description
_blank Opens the linked document in a new window.
_self Default. Open the linked document in the same frame.
_parent Opens the linked document in the parent frameset.
_top Opens the linked document throughout the window.
FrameName Opens the linked document in the specified frame.

HTML <a> Tags

HTML reference manual HTML instance HTML Quiz

The content provided by W3school is for training only. We do not guarantee the correctness of the content. The risks associated with the use of this site are not related to this site. W3school all contents of the Simplified Chinese version are for testing only and for any legal issues and risks

Target property for HTML <a> tags

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.