HTMLIFrameElement: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.

HTMLIFrameElement.referrerPolicy 属性表示了 <iframe> 元素的 referrerpolicy 属性,该属性定义了在获取资源时发送哪个引用者。

no-referrer

Referer 标头将被完全省略。请求时不会发送任何引用者信息。

no-referrer-when-downgrade

当协议安全级别保持不变(HTTP → HTTP、HTTPS → HTTPS)时,URL 作为引用者发送,但不会发送到安全性较低的目的地(HTTPS → HTTP)。

origin

在所有情况下仅发送文档的源作为引用者。https://example.com/page.html 文档将发送引用者 https://example.com/

origin-when-cross-origin

执行同源请求时发送完整的 URL,但在其他情况下仅发送文档的源。

same-origin

同源策略发送给引用者,但跨源请求将不包含引用者信息。

strict-origin

当协议安全级别保持不变(HTTPS → HTTPS)时仅发送文档的源作为引用者,但不发送到安全性较低的目的地(HTTPS → HTTP)。

strict-origin-when-cross-origin(默认值)

这是用户代理未指定策略时的默认行为。执行同源请求时发送完整的 URL,仅当协议安全级别保持不变(HTTPS → HTTPS)时发送源,并且不向安全性较低的目的地(HTTPS → HTTP)发送任何标头。

unsafe-url

当执行同源或跨源请求时发送完整的 URL。

备注: 此策略将把受 TLS 保护的资源的源和路径泄露给不安全的源。仔细考虑此设置的影响。

示例

js
const iframe = document.createElement("iframe");
iframe.src = "/";
iframe.referrerPolicy = "unsafe-url";
const body = document.querySelector("body");
body.appendChild(iframe); // 使用完整的 URL 作为引用源来获取图像

规范

Specification
HTML
# dom-iframe-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.

参见