From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/htmlanchorelement/download/index.html | 48 +++++ files/zh-cn/web/api/htmlanchorelement/index.html | 205 +++++++++++++++++++++ .../web/api/htmlanchorelement/referrer/index.html | 116 ++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 files/zh-cn/web/api/htmlanchorelement/download/index.html create mode 100644 files/zh-cn/web/api/htmlanchorelement/index.html create mode 100644 files/zh-cn/web/api/htmlanchorelement/referrer/index.html (limited to 'files/zh-cn/web/api/htmlanchorelement') diff --git a/files/zh-cn/web/api/htmlanchorelement/download/index.html b/files/zh-cn/web/api/htmlanchorelement/download/index.html new file mode 100644 index 0000000000..1d8c763510 --- /dev/null +++ b/files/zh-cn/web/api/htmlanchorelement/download/index.html @@ -0,0 +1,48 @@ +--- +title: HTMLAnchorElement.download +slug: Web/API/HTMLAnchorElement/download +tags: + - HTML属性 + - 下载 +translation_of: Web/API/HTMLAnchorElement/download +--- +
{{APIRef("HTML DOM")}}
+ +

HTMLAnchorElement.download属性是一个{{jsxref("DOMString")}} ,表明链接的资源将被下载,而不是显示在浏览器中。该值表示下载文件的建议名称。如果该名称不是基础操作系统的有效文件名,浏览器将对其进行调整。

+ +
+

注意: 该值对于下载行为来说不一定是有用的,同时也不能决定下载行为是否发生。

+
+ +

语法

+ +
var dnload = anchorElt.download;
+anchorElt.download = dnload;
+
+ +

规范Edit

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', 'multipage/text-level-semantics.html#dom-a-download', 'download')}}{{Spec2('HTML WHATWG')}}No change from {{SpecName("DOM2 HTML")}}
+ +

浏览器的兼容性

+ +
+ + +

{{Compat("api.HTMLAnchorElement.download")}}

+
diff --git a/files/zh-cn/web/api/htmlanchorelement/index.html b/files/zh-cn/web/api/htmlanchorelement/index.html new file mode 100644 index 0000000000..a5e8a72584 --- /dev/null +++ b/files/zh-cn/web/api/htmlanchorelement/index.html @@ -0,0 +1,205 @@ +--- +title: HTMLAnchorElement +slug: Web/API/HTMLAnchorElement +translation_of: Web/API/HTMLAnchorElement +--- +
{{APIRef("HTML DOM")}}
+ +

HTMLAnchorElement 接口表示超链接元素,并提供一些特别的属性和方法(除了那些继承自普通 {{domxref("HTMLElement")}}对象接口的之外)以用于操作这些元素的布局和显示。

+ +

属性(Properties)

+ +

继承其父类 {{domxref("HTMLElement")}} 的属性,并实现 {{domxref("URLUtils")}} 中(定义)的(属性)。

+ +
+
{{domxref("HTMLAnchorElement.accessKey")}}
+
是一个代表了单个字符的 {{domxref("DOMString")}},单个字符可以切换输入焦点到超链接。
+
{{domxref("HTMLAnchorElement.charset")}} {{obsolete_inline}}
+
Is a {{domxref("DOMString")}} representing the character encoding of the linked resource.
+
{{domxref("HTMLAnchorElement.coords")}} {{obsolete_inline}}
+
Is a {{domxref("DOMString")}} representing a comma-separated list of coordinates.
+
{{domxref("HTMLAnchorElement.download")}} {{experimental_inline}}
+
Is a {{domxref("DOMString")}} indicating that the linked resource is intended to be downloaded rather than displayed in the browser. The value represent the proposed name of the file. If the name is not a valid filename of the underlying OS, browser will adapt it. The value is a URL with a scheme like http:, file:, data: or even blob: (created with {{domxref("URL.createObjectURL")}}).
+
{{domxref("URLUtils.hash")}}
+
Is a {{domxref("DOMString")}} representing the fragment identifier, including the leading hash mark ('#'), if any, in the referenced URL.
+
{{domxref("URLUtils.host")}}
+
Is a {{domxref("DOMString")}} representing the hostname and port (if it's not the default port) in the referenced URL.
+
{{domxref("URLUtils.hostname")}}
+
Is a {{domxref("DOMString")}} representing the hostname in the referenced URL.
+
{{domxref("URLUtils.href")}}
+
Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("href", "a")}} HTML attribute, containing a valid URL of a linked resource.
+
{{domxref("HTMLAnchorElement.hreflang")}}
+
Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("hreflang", "a")}} HTML attribute, indicating the language of the linked resource.
+
{{domxref("HTMLAnchorElement.media")}}
+
Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("media", "a")}} HTML attribute, indicating the intended media for the linked resource.
+
{{domxref("HTMLAnchorElement.name")}} {{obsolete_inline}}
+
Is a {{domxref("DOMString")}} representing the anchor name.
+
{{domxref("URLUtils.passport")}}
+
Is a {{domxref("DOMString")}} 包含指定域名的密码。
+
{{domxref("URLUtils.origin")}} {{readonlyInline}}
+
Returns a {{domxref("DOMString")}} containing the origin of the URL, that is its scheme, its domain and its port.
+
{{domxref("URLUtils.pathname")}}
+
Is a {{domxref("DOMString")}} representing the path name component, if any, of the referenced URL.
+
{{domxref("URLUtils.port")}}
+
Is a {{domxref("DOMString")}} representing the port component, if any, of the referenced URL.
+
{{domxref("URLUtils.protocol")}}
+
Is a {{domxref("DOMString")}} representing the protocol component, including trailing colon (':'), of the referenced URL.
+
{{domxref("HTMLAnchorElement.rel")}}
+
Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("rel", "a")}} HTML attribute, specifying the relationship of the target object to the linked object.
+
{{domxref("HTMLAnchorElement.relList")}} {{readonlyInline}}
+
Returns a {{domxref("DOMTokenList")}} that reflects the {{htmlattrxref("rel", "a")}} HTML attribute, as a list of tokens.
+
{{domxref("HTMLAnchorElement.rev")}} {{obsolete_inline}}
+
Is a {{domxref("DOMString")}} representing that the {{htmlattrxref("rev", "a")}} HTML attribute, specifying the relationship of the link object to the target object.
+
{{domxref("URLUtils.search")}}
+
Is a {{domxref("DOMString")}} representing tThe search element, including leading question mark ('?'), if any, of the referenced URL.
+
{{domxref("HTMLAnchorElement.shape")}} {{obsolete_inline}}
+
Is a {{domxref("DOMString")}} representing the shape of the active area.
+
{{domxref("HTMLAnchorElement.tabindex")}}
+
Is a long containing the position of the element in the tabbing navigation order for the current document.
+
{{domxref("HTMLAnchorElement.target")}}
+
Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("target", "a")}} HTML attribute, indicating where to display the linked resource.
+
{{domxref("HTMLAnchorElement.text")}}
+
Is a {{domxref("DOMString")}} being a synonym for the {{domxref("Node.textContent")}} property.
+
{{domxref("HTMLAnchorElement.type")}}
+
Is a {{domxref("DOMString")}} that reflects the {{htmlattrxref("type", "a")}} HTML attribute, indicating the MIME type of the linked resource.
+
{{domxref("URLUtils.username")}}
+
Is a {{domxref("DOMString")}} containing the username specified before the domain name.
+
+ +

Methods

+ +

Inherits methods from its parent, {{domxref("HTMLElement")}}, and implements those from {{domxref("URLUtils")}}.

+ +
+
{{domxref("HTMLElement.blur()")}}
+
Removes the  keyboard focus from the current element.
+
{{domxref("HTMLElement.focus()")}}
+
Gives the keyboard focus to the current element.
+
{{domxref("URLUtils.toString()")}}
+
Returns a {{domxref("DOMString")}} containing the whole URL. It is a synonym for {{domxref("URLUtils.href")}}, though it can't be used to modify the value.
+
+ +

The blur() and focus() methods are inherited from {{domxref("HTMLElement")}} from HTML5 on, but were defined on HTMLAnchorElement in DOM Level 2 HTML and earlier specifications.

+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}{{Spec2('HTML WHATWG')}}The following property has been added: download.
+ Technically, the URL-related properties, media, host, hostname, pathname, port, protocol, search, and hash, have been moved to the {{domxref("URLUtils")}} interface, and HTMLAreaElement implements this interface.
{{SpecName('HTML5 W3C', "text-level-semantics.html#the-a-element", "HTMLAnchorElement")}}{{Spec2('HTML5 W3C')}}The methods blur() and focus(), as well as the properties tabindex and accessKey, are now defined on {{domxref("HTMLElement")}}.
+ The following properties are now obsolete: charset, coords, name, rev, and shape.
+ The following properties have been added: hash, host, hostname, media, pathname, port, protocol, relList, search, and text.
{{SpecName('DOM2 HTML', 'html.html#ID-48250443', 'HTMLAnchorElement')}}{{Spec2('DOM2 HTML')}}No change from {{SpecName("DOM1")}}.
{{SpecName('DOM1', 'level-one-html.html#ID-48250443', 'HTMLAnchorElement')}}{{Spec2('DOM1')}}Initial definition.
+ +

Browser compatibility

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatVersionUnknown}}{{CompatGeckoDesktop(1.0)}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
download1420{{CompatUnknown}}15{{CompatUnknown}}
username, password, and origin{{CompatUnknown}}{{CompatGeckoDesktop("26.0")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatGeckoMobile(1.0)}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
download{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
username, password, and origin{{CompatUnknown}}{{CompatGeckoMobile("26.0")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

See also

+ + diff --git a/files/zh-cn/web/api/htmlanchorelement/referrer/index.html b/files/zh-cn/web/api/htmlanchorelement/referrer/index.html new file mode 100644 index 0000000000..b3e30b3fe2 --- /dev/null +++ b/files/zh-cn/web/api/htmlanchorelement/referrer/index.html @@ -0,0 +1,116 @@ +--- +title: HTMLAnchorElement.referrer +slug: Web/API/HTMLAnchorElement/referrer +translation_of: Web/API/HTMLAnchorElement/referrerPolicy +--- +
{{APIRef}}{{SeeCompatTable}}
+ +

HTMLAnchorElement.referrer 属性对应于 HTML 中 {{HTMLElement("a")}} 标签的 {{htmlattrxref("referrer","a")}} 属性,它可以控制用户在点击这个链接时所发出的 HTTP 请求的 Referer 请求头的值。

+ +

语法

+ +
refStr = anchorElt.referrer;
+anchorElt.referrer = refStr;
+ +

属性值

+ +
+
+
    +
  • "no-referrer" 意味着不要发送 Referer 请求头。
  • +
  • "origin"  意味着所发送的 Referer 请求头的值为当前页面的源,即 location.origin 的值。
  • +
  • "unsafe-url" 意味着所发送的 Referrer 请求头的值为当前页面完整的 url(即 location.href)去掉尾部的哈希(即 location.hash)之后的值。正如该选项的名字所言(unsafe),此选项是不安全的,它可以将一个 HTTPS 页面的路径信息透露给第三方。
  • +
+
+
+ +

示例

+ +
var elt = document.createElement("a");
+var linkText = document.createTextNode("My link");
+elt.appendChild(linkText);
+elt.href = "https://developer.mozilla.org/en-US/";
+elt.referrer = "no-referrer";
+
+var div = document.getElementById("divAround");
+div.appendChild(elt); // 点击该链接接时不会发送 Referer 请求头
+
+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Referrer Policy', '#referrer-policy-delivery-referrer-attribute', 'referrer attribute')}}{{Spec2('Referrer Policy')}}Added the referrer attribute.
+ +

浏览器兼容性

+ +
{{CompatibilityTable}} +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoDesktop("42.0")}} [1]{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatUnknown}}{{CompatGeckoMobile("42.0")}} [1]{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +

[1] 该特性目前默认为关闭状态,请通过将 network.http.enablePerElementReferrer 选项设置为 true 来开启。

+
+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf