--- title: HTMLImageElement.referrerPolicy slug: Web/API/HTMLImageElement/referrerPolicy translation_of: Web/API/HTMLImageElement/referrerPolicy ---
{{APIRef}}{{SeeCompatTable}}

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

语法

refStr = imgElt.referrerPolicy;
imgElt.referrerPolicy = refStr;

例子

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

规范

Specification Status Comment
{{SpecName('Referrer Policy', '#referrer-policy-delivery-referrer-attribute', 'referrerPolicy attribute')}} {{Spec2('Referrer Policy')}} Added the referrerPolicy property.

浏览器兼容性

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome("51")}} {{CompatUnknown}} {{CompatGeckoDesktop("50.0")}} [1] {{CompatUnknown}} {{CompatOpera("38")}} {{CompatUnknown}}
Feature Android Webview Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatChrome("51")}} {{CompatChrome("51")}} {{CompatGeckoMobile("50.0")}} [1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

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

相关