12 References

12.1 Introduction to links and anchors

HTML offers a set of conditional speed for text and structured documents, but what distinguishes it from most other markup languages ​​- its ability to hypertext markup and interactive documents. This section introduces the link (or hyperlink or link Web), the basic hypertext construct. Links connect one with another Web resource. Despite the simplicity, the links have become a major key to Web success.

A link has two ends - known as the anchors - and a direction. The link starts at the "source" anchor (the source) and points to the "target" the anchor, which can be any resource Web (eg, images, video clips, sound files, applications, documents, HTML, an element in an HTML document, etc.).

12.1.1 The transition to a resource that is referenced

By default, citing related loading other resource Web. This behavior is typically achieved by selecting a link (e.g., a mouse click, keyboard input, etc.).

The following HTML-fragment contains two links , one from the target anchor is an HTML document with the name "chapter2.shtml", while the second target anchor - an image in GIF format, located in the file "forest.gif":

  <BODY>
 ... some text ... <P> See. <A href="chapter2.shtml"> in chapter two </A>. 
 See. Also <A href="../images/forest.gif"> forest map. </A>
 </ BODY>

By activating these links (by clicking with the mouse, through keyboard input, voice commands, etc.), users can navigate to these resources. Notice that the attribute href in each source anchor specifies the address of the target anchor using a URI.

Trust anchor link may be an element in the HTML document. Trust anchor must be given a name and a URI address, the anchor, must contain the name as a fragment identifier .

Target anchors in HTML documents may be specified by an element A (naming it with the attribute name ) or by any other element (naming with the attribute id ).

Thus, for example, the author can create a table of contents, elements of which are references to the elements of the headlines the H2 , the H3 , etc. in the same document. Using the element of A to create targeted anchors, can be written:

  <H1> Table of Contents; / H1>
 <P> <A href="#section1"> Introduction </A> <BR>
 <A Href="#section2"> Background </A> <BR>
 <A Href="#section2.1"> More specific notes </A> <BR>
 ... continued detention ... ... document body ... <H2> <A name="section1"> Introduction </A> </ H2>
 ... Section 1 ... <H2> <A name="section2"> Background </A> </ H2>
 ... Section 2 ... <H3> <A name="section2.1"> More specific notes </A> </ H3>
 ... section 2.1 ...
 

The same effect can be achieved by making anchors themselves header elements:

  <H1> Contents </ H1>
 <P> <A href="#section1"> Introduction </A> <BR>
 <A Href="#section2"> Background </A> <BR>
 <A Href="#section2.1"> More specific notes </A> <BR>
 ... continued detention ... ... document body ... <H2 id = "section1" > Introduction </ H2>
 ... Section 1 ... <H2 id = "section2" > Background </ H2>
 ... Section 2 ... <H3 id = "section2.1" > More specific notes </ H3>
 ... section 2.1 ...
 

12.1.2 Other link relationships

Reference is now most commonly used for other resource download Web, as shown in the previous examples. However, we can put in their papers references express other relationships between resources than simply "use the link to view the associated resource." For links that express other types of relationships, in the source anchor specifies one or more types of links .

Roles of links defined by an element of A or LINK are specified via the attribute rel and the rev .

For instance, links defined by an element of the LINK , can describe the position of a document in a series of documents. In the following example, the link in the "Chapter 5" indicates the previous and subsequent chapters:

  <HEAD>
 ... other header information ... <TITLE> Chapter 5 </ TITLE>
 <LINK rel = "prev" href = "chapter4.shtml">
 <LINK rel = "next" href = "chapter6.shtml">
 </ HEAD>

Type the first link - "prev", the second - "next" (two of several recognized link types ). References Asked elements LINK , are generated with the contents of the document, although the user agents may display them in various ways (for example, a transfer of funds).

Even if they are not used for transport, these links may be interpreted in interesting ways. For example, the user agent that performs a number of printing documents in HTML format into a single document, can use this information to form a sequential linear document. Further information on the use of links to search engines listed below.

12.1.3 Specifying anchors and links

Although some HTML elements and attributes create links to other resources (eg, item images IMG element FORM , etc.), this chapter discusses links and anchors created by the elements of the LINK and A . Element LINK can only be present in the document header. The element A may be present only in the body of the document.

If the element A set attribute of the href , this element defines the source anchor for a link that may be activated by the user to download Web resource. The source anchor - is the location of the instance element A and the target Web resource anchor.

The loaded resource can be handled by the user agent in various ways: opening a new HTML document in the same window agent, opening a new HTML document in a different window, starting a new program to handle the resource, etc. As an element of A has content (text, images, etc.), user agents can generate the content so as to show the existence of a link (for example, emphasizing the contents).

If attribute set name or id element A , the element defines an anchor that may be the destination of other links.

Authors can set the attributes name and href simultaneously in a single original element A .

Element LINK defines the relation between the current document and another resource. Although the element LINK has no content, it defines the relationship can be displayed by some user agents.

12.1.4 Headings links

The attribute title may be set for the element A , and the element the LINK ; it gives you information about the nature of links. This information may be spoken by a user agent, displayed as a tool tip, change the appearance of the cursor, etc.

Thus, you can augment the previous example , specifying a title for each link:

  <BODY>
 ... some text ... <P> You can read more about this in the <A href = "chapter2.shtml"
  title = "Go to Chapter 2"> Chapter 2 </A>.
 <A href = "./ chapter2.shtml"
  title = "Go to Chapter 2."> Chapter 2 </A>. 
 See. Also <A href = "../ images / forest.gif"
  title = "Forest GIF images"> Forest map. </A>
 </ BODY>

12.1.5 Internationalization and links

Since links may point to documents that use other character encodings , the elements of A and LINK support attribute the charset . This attribute allows authors to recommend that user agents encoding data in the linked document.

Attribute hreflang provides user agent information on language-related resources, in the same way as an attribute lang provides information about the language of an element's content or attribute values.

With additional knowledge, user agents should not be able to present the user with "garbage." Instead, they can find the resources necessary for proper presentation of the document or, if they can not find these resources, at least notify the user about the impossibility of reading a document stating the reason.

12.2 Element A

  <The ELEMENT! A - - ( % the inline; ) * - (A) - the anchor (reference point) ->
 <! ATTLIST A
  % attrs;
  - % Coreattrs , % the i18n , % events -
  the charset % Charset;
  #IMPLIED - The character encoding of linked resource -
  of the type % the ContentType;
  #IMPLIED - The recommended type of content -
  name a CDATA #IMPLIED - the end of the named links -
  the href % the URI;
  #IMPLIED - URI for linked resource -
  the hreflang % LanguageCode;
  #IMPLIED - The language code -
  the rel % LinkTypes;
  #IMPLIED - The types of direct links -
  the rev % LinkTypes;
  #IMPLIED - The types of backlinks -
  accesskey % the Character;
  #IMPLIED - Access key -
  shape % the Shape;
  the rect - for use with client cards -
  coords % Coords;
  #IMPLIED - For use with client cards -
  the tabindex NUMBER #IMPLIED - position in tabbing order -
  the onfocus % the Script;
  #IMPLIED - The focus on an element -
  the onblur % the Script;
  #IMPLIED - The element is the focus -
  >

Start tag: required, End tag: required

attribute definitions

name = cdata [the CS]
This attribute gives the name of the anchor so that it can serve another purpose of reference. The value of this attribute must be a unique name. The scope of a name - the current document. Note that this attribute uses a common namespace with the attribute id .
the href = the uri [the CT]
This attribute specifies the location of a resource Web, defining the relationship between the current element (the source anchor) and the destination anchor defined by this attribute.
the hreflang = langcode [the CI]
This attribute specifies the base language of the resource designated by attribute the href , and can be used only if the specified attribute of the href .
of the type = the content-of the type [the CI]
If this attribute is set, it determines the type of a piece of content, for example, reverse the result of action by reference to a resource. Content types are defined in section [MIMETYPES] .
the rel = link-types [the CI]
This attribute describes the relationship from the current document to the anchor specified by the attribute of the href . The value of this attribute is a space-separated list of link types.
the rev = link-types [the CI]
This attribute is used to describe a reverse link from the anchor specified by an attribute of the href , in the current document. The value of this attribute is a space-separated list of link types.
the charset = the charset [the CI]
This attribute specifies the character encoding of the resource designated by the link. See. In the section on character encodings .

Each element of A defines an anchor

  1. The content of the element A determines the position of the armature.
  2. Attribute name specifies the name of an anchor, so that it can serve as a destination for any number of links (see. As the anchor with the id attribute ).
  3. Attribute href assigns an anchor destination exactly one link.

Authors may also create an element of A , not determining a single anchor, and not pointing the href , name , or id . The values of these attributes may be set later using scripts.

In the following example, the element A determines the link. The source anchor is the text "Web-site W3C", and the destination - "http://www.w3.org/":

  For more information about W3C, please consult on 
 <A Href="http://www.w3.org/"> Web-site W3C </A>. 

This link points to a page World Wide Web Consortium. When a user activates this link in your agent, the agent loads the resource, in this case - the document HTML.

Typically, user agents are links so that they are obvious to the users (underscore, reverse video, etc.). The exact rendering depends on the user agent. Representation may vary depending on whether the user has already visited whether the link above. Possible visual representation of the previous link:

  For more information about W3C, please consult on the Web-site W3C.
  ~~~~~~~~~~~~~

To give user agents an explicit indication of the encoding target page character set attribute of the charset :

  For more information about W3C, please consult on
 <A Href="http://www.w3.org/" charset="ISO-8859-1"> Web-site W3C </A> 

Suppose we define an anchor named "anchor-one" in the file "one.shtml".

  ... text before the anchor ... <A name="anchor-one"> This is the location of anchor. </A>
 ... text after the anchor ...
 

In this passage around the text "This is the location of anchor" anchor is created. Typically, the contents of the element A is not in any particular way, if the element A defines an anchor only.

Having defined the anchor, we can link it to the same or another document. The URI, appointing anchor include the symbol "#" followed by an anchor name ( the fragment identifier ). Here are a few examples of such URI:

  • Absolute URI: http://www.mycompany.com/one.shtml#anchor-one
  • Relative URI: ./one.shtml#anchor-one or one.shtml # anchor-one
  • If the link is defined in the same document: # anchor-one

Thus, a link defined in the file "two.shtml", which is in the same directory as the file "one.shtml", will point to the anchor as follows:

  ... text before the link ... For details, see. <A href="./one.shtml#anchor-one"> first anchor </A>.
 ... text after the link ...
 

Element A in the following example specifies a link (via attribute the href ) and at the same time creates a named anchor (with the attribute name ):

  I just returned from vacation!  here is
 <A name = "anchor-two" 
  href = "http://www.somecompany.com/People/Ian/vacation/family.png">
 photo of my family at the lake. </A>.

In this example, a reference to a different type of Web resource (a PNG image). Activating the link should cause the image to download from the Web (and possibly display it if the system is configured accordingly).

Note. User agents should be able to find anchors created by empty elements A , but some agents can not do that. For example, some user agents may not find the "empty-anchor" in the following code HTML:

  <A Name="empty-anchor"> </A>
 <EM> ... some HTML text ... </ EM>
 <A Href="#empty-anchor"> Link to empty anchor </A>

12.2.1 Syntax name anchors

Anchor name is the value of the attribute name or attribute id , used in the context of anchors. To name anchors the following rules apply:

  • Uniqueness: Anchor names must be unique within the document. The names of the anchors in the same document may not only differ in case.
  • Match lines: Comparison between fragment identifiers and anchor names must be based on complete (case-sensitive) match.

Thus, the following example is correct in the sense of the line and should be treated as a match by user agents:

  <P> <A href="#xxx"> ... </A>
 ... some text ... <P> <A name="xxx"> ... </A>

ILLEGAL EXAMPLE:
The following example is not valid in the sense of uniqueness since the two names differ only by case:

  <P> <A name="xxx"> ... </A>
 <P> <A name="XXX"> ... </A>

Although the following provides a valid code HTML, users agent behavior in this case is not defined; some user agents may (incorrectly) consider this a coincidence, so others can not be considered.

  <P> <A href="#xxx"> ... </A>
 ... some text ... <P> <A name="XXX"> ... </A>

Anchor names must contain only ASCII characters. See. In the section on the use of characters, non-ASCII characters in URI attribute values .

12.2.2 Nested links are unacceptable

Links and anchors defined by the element A , can not be nested; element A may not contain other elements A .

Since the DTD defines the element LINK as an empty, elements of the LINK can also be nested.

12.2.3 Anchors with the id attribute

Attribute id can be used to create a start-tag anchors in each element (including an element A ).

This example shows how to use attribute id to accommodate the anchor element in the H2 . Communication with the anchor element by means of A .

  Read more about this you can read in the <A href="#section2"> Section 2 </A>.
 ... later in the document <H2 id = "section2"> Section 2 </ H2>
 ... later in the document <P> See. in <A href="#section2"> </A> Section 2 above.

In the following example, the name of the target anchor is set using the attribute id :

  I just returned from vacation!  here is
 <A Id="anchor-two"> photo of my family at the lake. </A>.

The attributes id and name using the same namespace. This means that they can not detect an anchor with the same name in the same document.

ILLEGAL EXAMPLE:
The following is a snippet of code is invalid HTML, since these attributes declare the same name twice in the same document.

  <A Href="#a1"> ... </A>
 ...
 <H1 id = "a1">
 ... pages and pages ... <A name="a1"> </A>

According to the specifications the HTML DTD attribute name may contain character references . Thus, the value of D & # xfc; rst is valid for the attribute name , as well as D & uuml; rst. Attribute id may not contain character references.

What to use - id or name ? When you select the element id or name to indicate the name of the anchor authors should bear in mind the following:

  • Attribute id may be not only the name of the anchor (as well as selector stylesheet processing identifier, etc.).
  • Some user agents older versions do not support anchors created with the attribute id .
  • Attribute name provides a variety of anchors names (with the entities ).

12.2.4 Unavailable and unidentifiable resources

Link to an unavailable or unidentifiable resource is an error. Although user agents may vary in how to handle such an error, we recommend the following behavior:

  • If the user agent can not locate a linked resource, it should notify the user.
  • If the user agent can not identify the type of a linked resource, it should try to treat it. He must notify the user and allow the user to intervene and identify the document type.

12.3 Document relationships: the element LINK

  <The ELEMENT! The LINK - About EMPTY The - independent of the link devices ->
 <! ATTLIST LINK
  % attrs;
  - % Coreattrs , % the i18n , % events -
  the charset % Charset;
  #IMPLIED - The character encoding of linked resource -
  the href % the URI;
  #IMPLIED - URI for linked resource -
  the hreflang % LanguageCode;
  #IMPLIED - The language code -
  of the type % the ContentType;
  #IMPLIED - The recommended type of content -
  the rel % LinkTypes;
  #IMPLIED - The type of direct communication -
  the rev % LinkTypes;
  #IMPLIED - The type of feedback -
  media % MediaDesc;
  #IMPLIED - For submission to these devices -
  >

Start tag: required, End tag: forbidden

This element defines the relationship. Unlike the element A , it may be present only in the section HEAD document, although any number of times can be present. Although the element LINK has no content, it contains information about the relationship that can be provided by user agents in a variety of ways (eg, in the form of a panel with a drop-down list of links).

This example shows how several definitions element LINK can be presented in the section HEAD of the document. The current document is "Chapter2.shtml". The attribute rel indicates the ratio of the linked document with the current document. The values "Index", "Next" and "Prev" are described in the section on link types .

  <DOCTYPE HTML PUBLIC! "- // W3C // DTD HTML 4.0 // EN"
  "Http://www.w3.org/TR/REC-html40/strict.dtd">
 <HTML>
 <HEAD>
  <TITLE> Chapter 2 </ TITLE>
  <LINK rel = "Index" href = "../ index.shtml">
  <LINK rel = "Next" href = "Chapter3.shtml">
  <LINK rel = "Prev" href = "Chapter1.shtml">
 </ HEAD>
 ... more document ...
 

12.3.1 Forward and reverse links

The attributes rel and rev play complementary roles - the attribute rel specifies a direct link, and attribute rev - reverse.

Consider two documents - A and B.

  Document A: <LINK href = "docB" rel = "foo">

It has exactly the same value, and that:

  Document B: <LINK href = "docA" rev = "foo">

Both attributes can be determined simultaneously.

12.3.2 Links and external style sheets

If the element LINK refers to an external style sheet to the document, the attribute type specifies the style sheet language, but the attribute media - estimated device or apparatus for presenting the document. User agents may save time by downloading from the network only those style sheets that apply to the current device.

Device types are discussed in the section on style sheets.

12.3.3 Links and search engines

Authors can use the element LINK to indicate a variety of information to search engines, including:

  • Links to alternate versions of a document written in other languages.
  • Links to alternate versions of a document designed for other devices, such as a version designed specifically for printing.
  • Links to the initial page set of documents.

The examples below show how language information, the types of devices and types of links can be used to improve document handling by search engines.

In the following example, we use attribute the hreflang , to tell search engines where to find Dutch, Portuguese and Arabic versions of a document. Note the use of the attributes dir and charset to guide in Arabic, as well as the use of the attribute lang to indicate that the value of the attribute title for the item the LINK , indicating manual in French, given in French.

  <HEAD>
 <TITLE> Manual in English </ TITLE>
 <LINK title = "in Dutch Guide"
  type = "text / html"
  rel = "alternate"
  hreflang = "nl" 
  href = "http://someplace.com/manual/dutch.shtml">
 <LINK title = "in Portuguese Guide"
  type = "text / html"
  rel = "alternate"
  hreflang = "pt" 
  href = "http://someplace.com/manual/portuguese.shtml">
 <LINK title = "Arabic Guide"
  dir = "rtl"
  type = "text / html"
  rel = "alternate"
  charset = "ISO-8859-6"
  hreflang = "ar" 
  href = "http://someplace.com/manual/arabic.shtml">
 <LINK lang = "fr" title = "La documentation en Fran & ccedil; ais"
  type = "text / html"
  rel = "alternate"
  hreflang = "fr"
  href = "http://someplace.com/manual/french.shtml">
 </ HEAD>

In the following example, we tell search engines where to find the printed version of the manual.

  <HEAD>
 <TITLE> Guide </ TITLE>
 <LINK media = "print" title = "Guide to postscript format"
  type = "application / postscript"
  rel = "alternate"
  href = "http://someplace.com/manual/postscript.ps">
 </ HEAD>

In the following example, we tell search engines where to find the first page of a set of documents.

  <HEAD>
 <TITLE> Manual - page 5 </ TITLE>
 <LINK rel = "Start" title = "Home management"
  type = "text / html"
  href = "http://someplace.com/manual/start.shtml">
 </ HEAD>

For further information, see the comments on the application of how to help search engines index your Web-site .

12.4 Path information: the element BASE

  <The ELEMENT! The BASE - About EMPTY The - the base URI of the document ->
 <! ATTLIST BASE
  the href % the URI;
  #REQUIRED - URI, the employee base -
  >

Start tag: required, End tag: forbidden

attribute definitions

the href = the uri [the CT]
This attribute specifies an absolute URI, serving base URI for resolving relative URI.

The attributes defined elsewhere

In HTML, links to external images, applets, form-processing programs, style sheets, etc. always defined by a URI. Relative URI resolved in accordance with the base URI, which may be determined from a variety of sources. Element BASE allows authors to explicitly specify the base URI of the document.

If the element BASE is specified, it must be present in the section HEAD of the document the HTML, to the elements that link to external resources. Information about the path specified in the element the BASE , affects only the URI in the document that this element is present.

For example, given the following declaration BASE and declaration A :

  <DOCTYPE HTML PUBLIC! "- // W3C // DTD HTML 4.0 // EN"
  "Http://www.w3.org/TR/REC-html40/strict.dtd">
 <HTML>
  <HEAD>
  <TITLE> Our Products </ TITLE>
  <BASE href = "http://www.aviary.com/products/intro.shtml">
  </ HEAD>
  <BODY>
  <P> Have you seen our <A cells href="../cages/birds.gif"> </A> for birds?
  </ BODY>
 </ HTML>

the relative URI "../cages/birds.gif" will be allowed in:

  http://www.aviary.com/cages/birds.gif

12.4.1 Resolution relative URI

User agents must calculate the base URI for resolving relative URI according to [RFC1808] , section 3. The following describes how [RFC1808] applies specifically to HTML.

User agents must calculate the base URI according to the following priority (from highest priority to lowest):

  1. The base URI, installed element the BASE .
  2. Base the URI, defined by metadata discovered during work on a protocol such as an HTTP header (see. [RFC2068] ).
  3. By default, the base URI is the URI of the current document. Not all HTML documents have a base URI (eg, HTML documents can be present in the e-mail address and can not be defined by any URI). Such HTML documents are considered erroneous, if they contain relative URI and use the default base URI.

In addition, elements of the OBJECT and APPLET define the attributes that have the advantage over the value set for the element of the BASE . For more information about their related definitions, see URI. In the definitions of these elements.

Links mentioned in the HTTP headers are handled exactly as elements of the LINK , clearly set out in the document.