Home  >  Article  >  Web Front-end  >  HTML anchors and links_html/css_WEB-ITnose

HTML anchors and links_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:46:011402browse

The difference between A element anchor and link

Anchor and link are both a elements. The only difference is whether there is href attribute.

In Firefox35 and Chrome41, as long as the a element has the name attribute, it is an anchor regardless of whether the name has a value or not. But in IE, if name has no value and no href, it is neither an anchor nor a link.

In all browsers, as long as the a element has the href attribute, it is a link regardless of whether it has a value or not.

Creation and function of anchor

The function of anchor is that when the last part of the URL is #anchorname, the browser will slide the scroll bar so that the anchor appears at the top of the visible window.

Creation method:

  • Create an a element and set a meaningful name to it;
  • Do not use the a element, but in On the required element, set a meaningful ID attribute for this element;
  • A link

    Four states of A link

    When the A element is used as a link, there are Four pseudo-classes: :link, :hover, :active, :visited, respectively corresponding to the four states of stillness, mouseover, clicked and after clicked.

    Download link

    Make the href attribute point to a file. As long as the user clicks, it can trigger the browser to download the file, but this is likely to trigger the browser to open a new window.

    The A element in HTML5 has an additional download attribute (assign the href value to this attribute). Use this attribute to download files. The browser does not need it. Open a new window to download the file directly.

    Specify the window to open the link

    The A element has a target attribute. This attribute is not a standard attribute in HTML4 strict mode, but because it is widely used, it has been recognized as a standard attribute in HTML5 property.

    The value of the Target attribute should be the name of the frame element, or one of _parent, _top, _self, _blank.

    HTML4 standard link opens in a new window

    Since target is not a standard attribute in HTML4, if the page complies with W3C standards, it cannot be used directly on the element. But we can use JavaScript to dynamically set the target attribute after the page is loaded.

    Notify interested third parties when a link is clicked

    This is a new feature added by HTML5. HTML5 adds a ping attribute to the A element . The value of the Ping attribute is a string of space-separated URLs. When the link is clicked, the browser will send a POST request to these URLs, indicating that the link has been clicked.

    But now only Chrome36 supports it.

    Cache target resources in advance

    resource

    Link link

    The Link link element has no closing tag, so it is placed in the head element.

    Load style file

    Set site icon

    Cache target resources in advance

    Others

  • If you set the href value for a, calling the click method in an old version of Firefox may not trigger a redirection.
  • In Chrome36, when the dispatchEvent() method is called, the a connection will also be redirected, but not in Firefox30.
  • Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn