aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlimageelement/referrerpolicy/index.html
blob: 8e34dfaa41a492cd43ad20e11878f6ac2c79f1de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
title: HTMLImageElement.referrerPolicy
slug: Web/API/HTMLImageElement/referrerPolicy
translation_of: Web/API/HTMLImageElement/referrerPolicy
---
<div>{{APIRef}}{{SeeCompatTable}}</div>



<p><code><strong>HTMLImageElement</strong></code><strong><code>.referrerPolicy</code></strong> 反映了 {{HTMLElement("img")}} 元素的HTML属性 {{htmlattrxref("referrerpolicy","img")}} 的定义,这个属性定义了{{HTMLElement("img")}} 元素在获取资源时的引用方式。</p>



<h2 id="语法">语法</h2>

<pre class="syntaxbox"><var>refStr</var> = <var>imgElt</var>.referrerPolicy;
<var>imgElt</var>.referrerPolicy = <var>refStr</var>;</pre>

<h3 id="值"></h3>

<dl>
 <dd>
 <ul>
  <li><code>"no-referrer"</code> 表示HTTP头部信息将不会发送 <code>referrer</code></li>
  <li><code>"origin"</code> 表示 referrer 只包含策略、主机名、端口等页面源的信息。</li>
  <li><code>"unsafe-url"</code> 这意味着引用者将包括源站和路径(但不包括片段、密码或用户名)。这种情况是不安全的,因为它可能会泄漏路径信息,这些信息已被使用TLS隐藏到第三方。</li>
 </ul>
 </dd>
</dl>

<h2 id="例子">例子</h2>

<pre class="brush: js;highlight:[3]">var img = new Image();
img.src = 'img/logo.png';
img.referrerPolicy = 'origin';

var div = document.getElementById('divAround');
div.appendChild(img); // Fetch the image using the origin as the referrer
</pre>

<h2 id="Specifications" name="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', 'referrerPolicy attribute')}}</td>
   <td>{{Spec2('Referrer Policy')}}</td>
   <td>Added the <code>referrerPolicy</code> property.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>

{{Compat("api.HTMLImageElement.referrerPolicy")}}

<h2 id="相关">相关</h2>

<ul>
 <li>{{domxref("HTMLAnchorElement.referrerPolicy")}}, {{domxref("HTMLAreaElement.referrerPolicy")}}, and {{domxref("HTMLIFrameElement.referrerPolicy")}}.</li>
</ul>