此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

HTMLFencedFrameElement:config 属性

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 <fencedframe> element and related APIs.

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

HTMLFencedFrameElementconfig 属性包含一个 FencedFrameConfig 对象,表示 <fencedframe> 的导航,即其中将显示什么内容。FencedFrameConfig 是从诸如受保护的受众 API 等来源返回的。

config 的初始值为 null

当值设置为 FencedFrameConfig 对象实例,FencedFrameConfig 的内部属性(例如 mappedURL)将决定所关联的 <fencedframe> 内部加载的内容。此外:

  • 导航类型将是 "replace"(参见 NavigateEvent.navigationType),这意味着当前历史记录条目将被新条目替换,而不是为其添加一个新的历史记录条目。
  • 导航的 Referrer-Policy 被设置为 "no-referrer"

示例

要设置将在 <fencedframe> 中显示的内容,使用 API(如受保护的受众共享存储)生成一个 FencedFrameConfig 对象,然后将其设置为 <fencedframe>config 属性值。

以下示例从受保护的受众 API 的广告拍卖中获取一个 FencedFrameConfig,然后使用它在 <fencedframe> 中显示获胜的广告:

js
const frameConfig = await navigator.runAdAuction({
  // 拍卖配置
  resolveToConfig: true,
});

const frame = document.createElement("fencedframe");
frame.config = frameConfig;

备注:在调用 runAdAuction() 时,必须传入 resolveToConfig: true 以获得 FencedFrameConfig 对象。如果没有设置,则所得的 Promise 将兑现为一个 URN,该 URN 只能在 <iframe> 中使用。

规范

规范
Fenced Frame
# dom-htmlfencedframeelement-config

浏览器兼容性

参见