What about hyperlinks (2): Attributes href and those href

Source: Internet
Author: User

What about hyperlinks (2): Attributes href and those href

One of the attributes of tag a, href

1. Definition

The href attribute is used to specify the URL of the hyperlink target.

2. Usage

①. Anchor

  • Add an anchor on the same page

(1) <a href = "# test"> connection to the anchor of the current page </a> // click

(2) <a name = "test"> anchor </a> // place it in the content to jump

  • Add an anchor across pages

(1)create an anchor in test2.html <a name = "test"> anchor </a>

(2)set the connection in test1.html <a href = "test2.html # test"> the hyperlink to the anchor of another page </a>

②. Download

<a href="download.rar"></a> 

The url in href must be valid, preferably in rar format.

3. Call

<A href = "tel: Phone Number"> </a>

  ④. Email

Email Tag:Mailto

Nature:Cc:CC

Bcc: Dark copy

Subject:Topic

Body:Email content

  • General

<A href = "mailto: xxx@xx.com"> </a>

  • Use commas (,) to send multiple addresses

<A href = "mailto: xxx@xx.com, xxx@xx.com"> </a>

  • Use attributes

<A href = "mailto: xxx@xx.com? Cc = xxx@xx.com & bcc = xxx@xx.com & subject = subject & body = content "> </a>

⑤. Javascript

  • Directly call javascript

<A href = "javascript: function_name ()"> </a>

The W3C standard does not recommend executing javascript statements in href. this method is prone to problems when passing this and other parameters, and javascript: when the protocol is used as the href attribute of a, not only does it cause unnecessary window triggering. the onbeforeunload event stops playing GIF animated images in IE.

  • Use void,:, undefined, with onclick

<A href = "javascript:" onclick = "function_name ()"> </a>

<A href = "javascript: void (0)" onclick = "function_name ()"> </a>

<A href = "javascript: undefined" onclick = "function_name ()"> </a>

The most common method is also the most comprehensive method. The Js method is not exposed in the address bar because the address does not jump.

  • '# 'And onclick

<A href = "#" onclick = "function_name ()"> </a>

'#' Is a built-in label method, which represents the role of top, so after executing the method, return to the top of the page.

<A href = "#" onclick = "function_name (); return false;"> </a>

After 'Return false' is executed, the page does not jump, and the page stays at the current position.

To be continued ....

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.