HTMLIFrameElement:browsingTopics 属性

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!

警告: 此特性目前遭到两家浏览器厂商反对。有关反对详情,请参阅标准立场部分。

HTMLIFrameElement 接口的 browsingTopics 属性是一个指定当前用户选择的主题应与之关联的 <iframe> 源请求一起以 Sec-Browsing-Topics 标头发送的布尔值。这反映了 browsingtopics HTML 属性。

有关更多详细信息,请参阅使用 Topics API

一个布尔值,默认值为 false;将其设置为 true 可使与 <iframe> 相关联的源请求携带一个包含当前用户选定主题的 Sec-Browsing-Topics 标头。

示例

获取

browsingtopics 设置为 true,然后以声明方式加载 <iframe> 的内容:

html
<iframe browsingtopics title="广告容器" src="adtech1.example"> ... </iframe>

通过脚本记录 browsingTopics 值:

js
const iframeElem = document.querySelector("iframe");
console.log(iframeElem.browsingTopics); // 将在支持的浏览器中返回 true

设置

指定最小的 <iframe>

html
<iframe> ... </iframe>

browsingtopics 设置为 true,然后通过脚本加载 <iframe> 内容:

js
const iframeElem = document.querySelector("iframe");

iframeElem.browsingTopics = true;
iframeElem.title = "广告容器";
iframeElem.src = "adtech1.example";

规范

此特性不属于官方标准,尽管它被定义在 Topics API 非官方建议草案中。

浏览器兼容性

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
browsingTopics
ExperimentalNon-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.

参见