aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/html/element/a/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-tw/web/html/element/a/index.html')
-rw-r--r--files/zh-tw/web/html/element/a/index.html313
1 files changed, 313 insertions, 0 deletions
diff --git a/files/zh-tw/web/html/element/a/index.html b/files/zh-tw/web/html/element/a/index.html
new file mode 100644
index 0000000000..91224a9318
--- /dev/null
+++ b/files/zh-tw/web/html/element/a/index.html
@@ -0,0 +1,313 @@
+---
+title: <a>
+slug: Web/HTML/Element/a
+translation_of: Web/HTML/Element/a
+---
+<p><span class="seoSummary"><strong>HTML <code>&lt;a&gt;</code> 元素</strong>(意為 Anchor)建立了通往其他頁面、檔案、Email 地址、或其他 URL 的超連結。</span></p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row"><a href="/zh-TW/docs/HTML/Content_categories">內容類型</a></th>
+ <td><a href="/zh-TW/docs/HTML/Content_categories#Flow_content">流型內容</a>、<a href="/zh-TW/docs/HTML/Content_categories#Phrasing_content">phrasing content</a>, <a href="/zh-TW/docs/Web/Guide/HTML/Content_categories#interactive_content">interactive content</a>, palpable content.</td>
+ </tr>
+ <tr>
+ <th scope="row">內容省略</th>
+ <td><a href="/zh-TW/docs/HTML/Content_categories#Transparent_content_model">Transparent</a>, containing either <a href="/zh-TW/docs/HTML/Content_categories#Flow_content">flow content</a> (excluding <a href="/zh-TW/docs/Web/Guide/HTML/Content_categories#interactive_content">interactive content</a>) or <a href="/zh-TW/docs/HTML/Content_categories#Phrasing_content">phrasing content</a>.</td>
+ </tr>
+ <tr>
+ <th scope="row">標籤省略</th>
+ <td>{{no_tag_omission}}</td>
+ </tr>
+ <tr>
+ <th scope="row">允許的父元素</th>
+ <td>任何允許 <a href="/zh-TW/docs/HTML/Content_categories#Phrasing_content">phrasing content</a> 或 <a href="/zh-TW/docs/HTML/Content_categories#Flow_content">flow content</a> 的內容,但 &lt;a&gt; 永遠例外(according to the logical principle of symmetry, if &lt;a&gt; tag, as a parent, can not have <a href="/en-US/docs/Web/Guide/HTML/Content_categories#interactive_content">interactive content</a>, then the same &lt;a&gt; content can not have &lt;a&gt; tag as its parent)</td>
+ </tr>
+ <tr>
+ <th scope="row">Permitted ARIA roles</th>
+ <td>{{ARIARole("button")}}, {{ARIARole("checkbox")}}, {{ARIARole("menuitem")}}, {{ARIARole("menuitemcheckbox")}}, {{ARIARole("menuitemradio")}}, {{ARIARole("option")}}, {{ARIARole("radio")}}, {{ARIARole("switch")}}, {{ARIARole("tab")}}, {{ARIARole("treeitem")}}</td>
+ </tr>
+ <tr>
+ <th scope="row">DOM 介面</th>
+ <td>{{domxref("HTMLAnchorElement")}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="屬性">屬性</h2>
+
+<p>本元素包含<a href="/zh-TW/docs/HTML/Global_attributes">全域屬性</a>。</p>
+
+<dl>
+ <dt>{{htmlattrdef("download")}} {{HTMLVersionInline(5)}}</dt>
+ <dd>This attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want). There are no restrictions on allowed values, though <code>/</code> and <code>\</code> are converted to underscores. Most file systems limit some punctuation in file names, and browsers will adjust the suggested name accordingly.
+ <div class="note"><strong>Notes:</strong>
+ <ul>
+ <li>This attribute only works for <a href="/en-US/docs/Web/Security/Same-origin_policy">same-origin URLs</a>.</li>
+ <li>This attribute can be used with <a href="/en-US/docs/Web/API/URL.createObjectURL"><code>blob:</code> URLs</a> and <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"><code>data:</code> URLs</a> to download content generated by JavaScript, such as pictures created in an image-editor Web app.</li>
+ <li>If the HTTP header <a href="/en-US/docs/Web/HTTP/Headers/Content-Disposition"><code>Content-Disposition:</code></a> gives a different filename than this attribute, the HTTP header takes priority over this attribute.</li>
+ <li>If <code>Content-Disposition:</code> is set to <code>inline</code>, Firefox prioritizes <code>Content-Disposition</code>, like the filename case, while Chrome prioritizes the <code>download</code> attribute.</li>
+ </ul>
+ </div>
+ </dd>
+ <dt>{{htmlattrdef("href")}}</dt>
+ <dd>Contains a URL or a URL fragment that the hyperlink points to.</dd>
+ <dd>A URL fragment is a name preceded by a hash mark (<code>#</code>), which specifies an internal target location (an <a href="/en-US/docs/HTML/Global_attributes#attr-id">ID</a> of an HTML element) within the current document. URLs are not restricted to Web (HTTP)-based documents, but can use any protocol supported by the browser. For example, <a class="external" href="https://en.wikipedia.org/wiki/File_URI_scheme"><code>file:</code></a>, <code>ftp:</code>, and <code>mailto:</code> work in most browsers.</dd>
+ <dd>This attribute may be omitted (as of HTML5) to create a placeholder link. A placeholder link resembles a traditional hyperlink, but does not lead anywhere.
+ <div class="note">
+ <p><strong>Note:</strong> You can use <code>href="#top"</code> or the empty fragment <code>href="#"</code> to link to the top of the current page. <a href="https://www.w3.org/TR/html5/single-page.html#scroll-to-fragid">This behavior is specified by HTML5</a>.</p>
+ </div>
+ </dd>
+ <dt>{{htmlattrdef("hreflang")}}</dt>
+ <dd>This attribute indicates the human language of the linked resource. It is purely advisory, with no built-in functionality. Allowed values are determined by <a class="external" href="https://www.ietf.org/rfc/bcp/bcp47.txt" title="Tags for Identifying Languages">BCP47</a>.</dd>
+ <dt>{{htmlattrdef("ping")}}</dt>
+ <dd>Contains a space-separated list of URLs to which, when the hyperlink is followed, {{HTTPMethod("POST")}} requests with the body <code>PING</code> will be sent by the browser (in the background). Typically used for tracking.</dd>
+ <dt>{{htmlattrdef("referrerpolicy")}} {{experimental_inline}}</dt>
+ <dd>Indicates which <a href="/en-US/docs/Web/HTTP/Headers/Referer">referrer</a> to send when fetching the URL:
+ <ul>
+ <li><code>'no-referrer'</code> means the <code>Referer:</code> header will not be sent.</li>
+ <li><code>'no-referrer-when-downgrade'</code> means no <code>Referer:</code> header will be sent when navigating to an origin without HTTPS. This is the default behavior.</li>
+ <li><code>'origin'</code> means the referrer will be the <a href="/en-US/docs/Glossary/Origin">origin</a> of the page, not including information after the domain.</li>
+ <li><code>'origin-when-cross-origin'</code> meaning that navigations to other origins will be limited to the scheme, the host and the port, while navigations on the same origin will include the referrer's path.</li>
+ <li><code>'unsafe-url'</code> means the referrer will include the origin and path, but not the fragment, password, or username. This is unsafe because it can leak data from secure URLs to insecure ones.</li>
+ </ul>
+ </dd>
+ <dt>{{htmlattrdef("rel")}}</dt>
+ <dd>Specifies the relationship of the target object to the link object. The value is a space-separated list of <a href="/en-US/docs/Web/HTML/Link_types">link types</a>.</dd>
+ <dt>{{htmlattrdef("target")}}</dt>
+ <dd>Specifies where to display the linked URL. It is a name of, or keyword for, a <em>browsing context</em>: a tab, window, or <code>&lt;iframe&gt;</code>. The following keywords have special meanings:
+ <ul>
+ <li><code>_self</code>: Load the URL into the same browsing context as the current one. This is the default behavior.</li>
+ <li><code>_blank</code>: Load the URL into a new browsing context. This is usually a tab, but users can configure browsers to use new windows instead.</li>
+ <li><code>_parent</code>: Load the URL into the parent browsing context of the current one. If there is no parent, this behaves the same way as <code>_self</code>.</li>
+ <li><code>_top</code>: Load the URL into the top-level browsing context (that is, the "highest" browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this behaves the same way as <code>_self</code>.</li>
+ </ul>
+
+ <div class="note">
+ <p><strong>Note:</strong> When using <code>target</code>, consider adding <code>rel="noopener noreferrer"</code> to avoid exploitation of the <code>window.opener</code> API.</p>
+ </div>
+ </dd>
+ <dt>{{htmlattrdef("type")}}</dt>
+ <dd>Specifies the media type in the form of a {{Glossary("MIME type")}} for the linked URL. It is purely advisory, with no built-in functionality.</dd>
+</dl>
+
+<h3 id="Obsolete">Obsolete</h3>
+
+<dl>
+ <dt>{{htmlattrdef("charset")}} {{obsoleteGeneric("inline","HTML5")}}</dt>
+ <dd>This attribute defined the <a href="/en-US/docs/Glossary/character_encoding">character encoding</a> of the linked URL. The value should be a space- and/or comma-delimited list of character sets defined in <a class="external" href="https://tools.ietf.org/html/rfc2045">RFC 2045</a>. The default value is <code>ISO-8859-1</code>.
+ <div class="note">
+ <p><strong>Usage note:</strong> This attribute is obsolete in HTML5 and <strong>should not be used by authors</strong>. To achieve its effect, use the HTTP <a href="/en-US/docs/Web/HTTP/Headers/Content-Type"><code>Content-Type:</code></a> header on the linked URL.</p>
+ </div>
+ </dd>
+ <dt>{{htmlattrdef("coords")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}</dt>
+ <dd>For use with the below <code>shape</code> attribute, this attribute used a comma-separated list of numbers to define the coordinates of the link on the page.</dd>
+ <dt>{{htmlattrdef("name")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}</dt>
+ <dd>This attribute was required for anchors defining a possible target location within a page. In HTML 4.01, <code>id</code> and <code>name</code> could be used simultaneously on a <code>&lt;a&gt;</code> element as long as they have identical values.
+ <div class="note">
+ <p><strong>Usage note:</strong> This attribute is obsolete in HTML5, use the <a href="/en-US/docs/HTML/Global_attributes#attr-id">global attribute <code>id</code></a> instead.</p>
+ </div>
+ </dd>
+ <dt>{{htmlattrdef("rev")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}</dt>
+ <dd>This attribute specified a reverse link, the inverse relationship of the <strong>rel</strong> attribute. It was deprecated for being very confusing.</dd>
+ <dt>{{htmlattrdef("shape")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline","HTML5")}}</dt>
+ <dd>This attribute was used to define a region for hyperlinks to create an image map. The values are <code>circle</code>, <code>default</code>, <code>polygon</code>, and <code>rect</code>. The format of the <strong>coords</strong> attribute depends on the value of shape. For <code>circle</code>, the value is <code>x,y,r</code> where <code>x</code> and <code>y</code> are the pixel coordinates for the center of the circle and <code>r</code> is the radius value in pixels. For <code>rect</code>, the <strong>coords</strong> attribute should be <code>x,y,w,h</code>. The <code>x,y</code> values define the upper-left-hand corner of the rectangle, while <code>w</code> and <code>h</code> define the width and height respectively. A value of <code>polygon</code> for <strong>shape</strong> requires <code>x1,y1,x2,y2,...</code> values for <strong>coords</strong>. Each of the <code>x,y</code> pairs defines a point in the polygon, with successive points being joined by straight lines and the last point joined to the first. The value <code>default</code> for shape requires that the entire enclosed area, typically an image, be used.
+ <div class="note"><strong>Note:</strong> Use the <a href="/en-US/docs/Web/HTML/Element/img#attr-usemap"><code>usemap</code> attribute</a> for the {{HTMLElement("img")}} element and the associated {{HTMLElement("map")}} element to define hotspots instead of the <code>shape</code> attribute.</div>
+ </dd>
+</dl>
+
+<h2 id="Examples">Examples</h2>
+
+<h3 id="Linking_to_an_external_location">Linking to an external location</h3>
+
+<pre class="brush: html">&lt;!-- anchor linking to external file --&gt;
+&lt;a href="https://www.mozilla.com/"&gt;
+External Link
+&lt;/a&gt;
+</pre>
+
+<h4 id="Result">Result</h4>
+
+<p><a class="external" href="https://www.mozilla.com/">External Link</a></p>
+
+<h3 id="Linking_to_another_section_on_the_same_page">Linking to another section on the same page</h3>
+
+<pre class="brush: html">&lt;!-- links to element on this page with id="attr-href" --&gt;
+&lt;a href="#attr-href"&gt;
+Description of Same-Page Links
+&lt;/a&gt;
+</pre>
+
+<h4 id="Result_2">Result</h4>
+
+<p><a href="#attr-href">Description of Same Page Links</a></p>
+
+<h3 id="Creating_a_clickable_image">Creating a clickable image</h3>
+
+<p>This example uses an image to link to the MDN home page. The home page will open in a new browsing context, that is, a new page or a new tab.</p>
+
+<pre class="brush: html">&lt;a href="https://developer.mozilla.org/en-US/" target="_blank"&gt;
+ &lt;img src="https://mdn.mozillademos.org/files/6851/mdn_logo.png"
+ alt="MDN logo" /&gt;
+&lt;/a&gt;
+</pre>
+
+<h4 id="Result_3">Result</h4>
+
+<figure>
+<p>{{EmbedLiveSample("Creating_a_clickable_image", "320", "64")}}</p>
+</figure>
+
+<h3 id="Creating_an_email_link">Creating an email link</h3>
+
+<p>It's common to create links that open in the user's email program to allow them to send a new message. This is done with a <code>mailto:</code> link. Here's a simple example:</p>
+
+<pre class="brush: html">&lt;a href="mailto:nowhere@mozilla.org"&gt;Send email to nowhere&lt;/a&gt;</pre>
+
+<h4 id="Result_4">Result</h4>
+
+<p><a href="mailto:nowhere@mozilla.org">Send email to nowhere</a></p>
+
+<p>For additional details about the <code>mailto</code> URL scheme, such as including the subject, body, or other predetermined content, see <a href="/en-US/docs/Web/Guide/HTML/Email_links">Email links</a> or {{RFC(6068)}}.</p>
+
+<h3 id="Creating_a_phone_link">Creating a phone link</h3>
+
+<p>Offering phone links is helpful for users viewing web documents and laptops connected to phones.</p>
+
+<pre class="brush: html">&lt;a href="tel:+491570156"&gt;+49 157 0156&lt;/a&gt;</pre>
+
+<p>For additional details about the <code>tel</code> URL scheme, see {{RFC(3966)}}.</p>
+
+<h3 id="Using_the_download_attribute_to_save_a_&lt;canvas>_as_a_PNG">Using the <code>download</code> attribute to save a <code>&lt;canvas&gt;</code> as a PNG</h3>
+
+<p>If you want to let users download an HTML {{HTMLElement("canvas")}} element as an image, you can create a link with a <code>download</code> attribute and the canvas data as a file URL:</p>
+
+<pre class="brush: js">var link = document.createElement('a');
+link.textContent = 'download image';
+
+link.addEventListener('click', function(ev) {
+ link.href = canvas.toDataURL();
+ link.download = "mypainting.png";
+}, false);
+
+document.body.appendChild(link);</pre>
+
+<p>You can see this in action at <a href="https://jsfiddle.net/codepo8/V6ufG/2/">jsfiddle.net/codepo8/V6ufG/2/</a>.</p>
+
+<h2 id="Notes">Notes</h2>
+
+<p>HTML 3.2 defines only the <code>name</code>, <code>href</code>, <code>rel</code>, <code>rev</code>, and <code>title</code> attributes.</p>
+
+<h3 id="Accessibility_recommendations">Accessibility recommendations</h3>
+
+<p>Anchor tags are often abused with the <code>onclick</code> event to create pseudo-buttons by setting <strong>href</strong> to <code>"#"</code> or <code>"javascript:void(0)"</code> to prevent the page from refreshing. These values cause unexpected behavior when copying/dragging links, opening links in a new tabs/windows, bookmarking, and when JavaScript is still downloading, errors out, or is disabled. This also conveys incorrect semantics to assistive technologies (e.g., screen readers). In these cases, it is recommended to use a {{HTMLElement("button")}} instead. In general you should only use an anchor for navigation using a proper URL. </p>
+
+<h3 id="Clicking_and_focus">Clicking and focus</h3>
+
+<p>Whether clicking on an {{HTMLElement("a")}} causes it to become focused varies by browser and OS.</p>
+
+<table>
+ <caption>Does clicking on an {{HTMLElement("a")}} give it focus?</caption>
+ <tbody>
+ <tr>
+ <td>Desktop Browsers</td>
+ <th>Windows 8.1</th>
+ <th>OS X 10.9</th>
+ </tr>
+ <tr>
+ <th>Firefox 30.0</th>
+ <td style="background-color: LawnGreen;">Yes</td>
+ <td style="background-color: LawnGreen;">Yes</td>
+ </tr>
+ <tr>
+ <th>Chrome ≥39<br>
+ (<a href="https://code.google.com/p/chromium/issues/detail?id=388666" title="Issue 388666: Focus anchor (A) elements on mousedown">Chromium bug 388666</a>)</th>
+ <td style="background-color: LawnGreen;">Yes</td>
+ <td style="background-color: LawnGreen;">Yes</td>
+ </tr>
+ <tr>
+ <th>Safari 7.0.5</th>
+ <td style="background-color: silver;">N/A</td>
+ <td style="background-color: yellow;">Only when it has a <code>tabindex</code></td>
+ </tr>
+ <tr>
+ <th>Internet Explorer 11</th>
+ <td style="background-color: LawnGreen;">Yes</td>
+ <td style="background-color: silver;">N/A</td>
+ </tr>
+ <tr>
+ <th>Presto (Opera 12)</th>
+ <td style="background-color: LawnGreen;">Yes</td>
+ <td style="background-color: LawnGreen;">Yes</td>
+ </tr>
+ </tbody>
+</table>
+
+<table>
+ <caption>Does tapping on an {{HTMLElement("a")}} give it focus?</caption>
+ <tbody>
+ <tr>
+ <td>Mobile Browsers</td>
+ <th>iOS 7.1.2</th>
+ <th>Android 4.4.4</th>
+ </tr>
+ <tr>
+ <th>Safari Mobile</th>
+ <td style="background-color: yellow;">Only when it has a <code>tabindex</code></td>
+ <td style="background-color: silver;">N/A</td>
+ </tr>
+ <tr>
+ <th>Chrome 35</th>
+ <td>???</td>
+ <td style="background-color: yellow;">Only when it has a <code>tabindex</code></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('Referrer Policy', '#referrer-policy-delivery-referrer-attribute', 'referrer attribute')}}</td>
+ <td>{{Spec2('Referrer Policy')}}</td>
+ <td>Added the <code>referrer</code> attribute.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'semantics.html#the-a-element', '&lt;a&gt;')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML5 W3C', 'text-level-semantics.html#the-a-element', '&lt;a&gt;')}}</td>
+ <td>{{Spec2('HTML5 W3C')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML4.01', 'struct/links.html#h-12.2', '&lt;a&gt;')}}</td>
+ <td>{{Spec2('HTML4.01')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("html.elements.a")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>Other elements conveying <a href="/en-US/docs/HTML/Text_level_semantics_conveying_elements">text-level semantics</a>: {{HTMLElement("abbr")}}, {{HTMLElement("em")}}, {{HTMLElement("strong")}}, {{HTMLElement("small")}}, {{HTMLElement("cite")}}, {{HTMLElement("q")}}, {{HTMLElement("dfn")}}, {{HTMLElement("time")}}, {{HTMLElement("code")}}, {{HTMLElement("var")}}, {{HTMLElement("samp")}}, {{HTMLElement("kbd")}}, {{HTMLElement("sub")}}, {{HTMLElement("sup")}}, {{HTMLElement("b")}}, {{HTMLElement("i")}}, {{HTMLElement("mark")}}, {{HTMLElement("ruby")}}, {{HTMLElement("rp")}}, {{HTMLElement("rt")}}, {{HTMLElement("bdo")}}, {{HTMLElement("span")}}, {{HTMLElement("br")}}, {{HTMLElement("wbr")}}.</li>
+</ul>
+
+<div>{{HTMLRef}}</div>