HTMLImageElement.referrerPolicy

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.

* Some parts of this feature may have varying levels of support.

HTMLImageElement.referrerPolicy 反映了 <img> 元素的 HTML 属性 referrerpolicy 的定义,这个属性定义了<img> 元素在获取资源时的引用方式。

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

示例

js
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
HTML
# dom-img-referrerpolicy

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
referrerPolicy
no-referrer-when-downgrade
origin-when-cross-origin
unsafe-url

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Uses a non-standard name.
Has more compatibility info.

参见