aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlimageelement/referrerpolicy/index.html
blob: c670d136f3f8d23334060a82a49adc7f08efa6d3 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
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>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome("51")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("50.0")}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatOpera("38")}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome("51")}}</td>
   <td>{{CompatChrome("51")}}</td>
   <td>{{CompatGeckoMobile("50.0")}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] 从火狐45到50,这都是在network.http.enableperelementerfer首选项之后。从火狐42到44,这个属性被称为referer。</p>

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

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