HTMLScriptElement: referrerPolicy property
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
* Some parts of this feature may have varying levels of support.
ThereferrerPolicy property of theHTMLScriptElement interface reflects the HTMLreferrerpolicy of the<script> element, which defines how the referrer is set when fetching the script and any scripts it imports.
In this article
Value
A string; one of the following:
no-referrerThe
Refererheader will be omitted entirely. No referrerinformation is sent along with requests.no-referrer-when-downgradeThe URL is sentas a referrer when the protocol security level stays the same (e.g.HTTP→HTTP,HTTPS→HTTPS), but isn't sent to a less secure destination (e.g., HTTPS→HTTP).
originOnly send the origin of the document as the referrer in all cases.The document
https://example.com/page.htmlwill send the referrerhttps://example.com/.origin-when-cross-originSend a full URL when performing a same-origin request, but only send the origin ofthe document for other cases.
same-originA referrer will be sent forsame-site origins, butcross-origin requests will contain no referrer information.
strict-originOnly send the origin of the document as the referrer when the protocol securitylevel stays the same (e.g., HTTPS→HTTPS), but don't send it to a less securedestination (e.g., HTTPS→HTTP).
strict-origin-when-cross-origin(default)This is the user agent's default behavior if no policy is specified. Send a full URL when performing a same-origin request, only send the origin when theprotocol security level stays the same (e.g., HTTPS→HTTPS), and send no header to aless secure destination (e.g., HTTPS→HTTP).
unsafe-urlSend a full URL when performing a same-origin or cross-origin request. This policywill leak origins and paths from TLS-protected resources to insecure origins.Carefully consider the impact of this setting.
Note:An empty string value ("") is both the defaultvalue, and a fallback value ifreferrerpolicy is not supported. Ifreferrerpolicy is not explicitly specified on the<script> element, it will adopt a higher-level referrer policy,i.e., one set on the whole document or domain. If a higher-level policy is notavailable, the empty string is treated as being equivalent tono-referrer-when-downgrade.
Examples
const scriptElem = document.createElement("script");scriptElem.src = "/";scriptElem.referrerPolicy = "unsafe-url";document.body.appendChild(scriptElem);Specifications
| Specification |
|---|
| HTML> # dom-script-referrerpolicy> |