HTML DOM
[!WARNING] 此特性目前遭到两家浏览器厂商反对。有关反对详情,请参阅标准立场部分。
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 非官方建议草案中。
浏览器兼容性
参见
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
