HTMLIFrameElement:browsingTopics 属性
Deprecated
To be removed
This feature is pending removal from browsers. Using it now may lead to broken functionality in future updates. Following the announcement that Chrome will maintain its current approach to third-party cookies, Chrome decided to withdraw certain Privacy Sandbox features including the topics API. >
非标准: 该特性尚未标准化。我们不建议在生产环境中使用非标准特性,因为它们在浏览器中的支持有限,且可能发生变化或被移除。不过,在没有标准选项的特定情况下,它们可以作为合适的替代方案。
警告:此特性目前遭到两家浏览器厂商反对。有关反对详情,请参阅标准立场部分。
HTMLIFrameElement 接口的 browsingTopics 属性是一个指定当前用户选择的主题应与之关联的 <iframe> 源请求一起以 Sec-Browsing-Topics 标头发送的布尔值。这反映了 browsingtopics HTML 属性。
有关更多详细信息,请参阅使用 Topics API。
值
一个布尔值,默认值为 false;将其设置为 true 可使与 <iframe> 相关联的源请求携带一个包含当前用户选定主题的 Sec-Browsing-Topics 标头。
示例
>获取
将 browsingtopics 设置为 true,然后以声明方式加载 <iframe> 的内容:
<iframe browsingtopics title="广告容器" src="adtech1.example"> ... </iframe>
通过脚本记录 browsingTopics 值:
const iframeElem = document.querySelector("iframe");
console.log(iframeElem.browsingTopics); // 将在支持的浏览器中返回 true
设置
指定最小的 <iframe>:
<iframe> ... </iframe>
将 browsingtopics 设置为 true,然后通过脚本加载 <iframe> 内容:
const iframeElem = document.querySelector("iframe");
iframeElem.browsingTopics = true;
iframeElem.title = "广告容器";
iframeElem.src = "adtech1.example";
规范
此特性不属于官方标准,尽管它被定义在 Topics API 非官方建议草案中。