HTMLAnchorElement: attributionSrc 属性
HTMLAnchorElement 接口的 attributionSrc 属性以编程方式获取和设置 <a> 元素上的 attributionsrc 属性,反映该属性的值。attributionsrc 指定您希望浏览器发送 Attribution-Reporting-Eligible 标头。在服务器端,这用于触发在响应中发送 Attribution-Reporting-Register-Source 标头,以注册一个基于导航的归因来源。
当浏览器接收到导航响应时,它会存储与基于导航的归因来源相关联的来源数据(如 Attribution-Reporting-Register-Source 响应标头中所提供)。
有关更多详细信息,请参阅 归因报告 API。
注意: <a> 元素不能用作归因触发器,只能用作来源。
值
一个字符串。此属性有两个版本可供获取和设置。
-
空字符串,即
aElem.attributionSrc=""。这指定您希望将Attribution-Reporting-Eligible标头发送到href属性指向的同一服务器。当您在同一服务器上处理归因来源注册时,这是可以的。 -
包含一个或多个 URL 的值,例如
jsaElem.attributionSrc = "https://a.example/register-source https://b.example/register-source";这在所请求的资源不在您控制的服务器上,或者您只想在不同的服务器上处理归因来源注册的情况下很有用。在这种情况下,您可以将一个或多个 URL 指定为
attributionSrc的值。当发生资源请求时,除了资源来源之外,Attribution-Reporting-Eligible标头还将发送到attributionSrc中指定的 URL。这些 URL 然后可以响应Attribution-Reporting-Register-Source来注册来源。注意:指定多个 URL 意味着可以在同一功能上注册多个归因源。例如,您可能正在尝试衡量不同广告系列的成功,这涉及生成关于不同数据的不同报告。
示例
设置空的 attributionSrc
<a href="https://shop.example"> Click to visit our shop </a>
const aElem = document.querySelector("a");
aElem.attributionSrc = "";
设置包含 URL 的 attributionSrc
<a href="https://ourshop.example"> Click to visit our shop </a>
// encode the URLs in case they contain special characters
// such as '=' that would be improperly parsed.
const encodedUrlA = encodeURIComponent("https://a.example/register-source");
const encodedUrlB = encodeURIComponent("https://b.example/register-source");
const aElem = document.querySelector("a");
aElem.attributionSrc = `${encodedUrlA} ${encodedUrlB}`;
规范
| 规范 |
|---|
| 归因报告 # dom-htmlattributionsrcelementutils-attributionsrc |
浏览器兼容性
加载中…