HTMLIFrameElement:credentialless 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

HTMLIFrameElement 接口的 credentialless 属性表示 <iframe> 是否无凭据,这意味着其中的文档将使用新的临时上下文加载。

这些上下文无法访问与其源关联的网络、cookie 和存储数据。相反,它们使用与顶层文档生命周期相关的新的上下文。这意味着用户导航离开页面或重新加载页面后,任何存储的数据都将不可访问。

作为回报,设置了 Cross-Origin-Embedder-Policy(COEP)的文档可以取消第三方文档的嵌入规则,这些第三方文档没有设置 COEP。有关更深入的解释,请参阅无凭据 IFrame

一个布尔值。默认值为 false;将其设为 true 可使 <iframe> 为无凭据。

示例

获取

像这样指定一个无凭据的 <iframe>

html
<iframe
  src="https://zh.wikipedia.org/wiki/幽灵漏洞"
  title="维基百科页面中的幽灵漏洞"
  width="960"
  height="600"
  credentialless></iframe>

返回 credentialless 属性值:

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

设置

或者,在 HTML 中指定最少的详细信息:

html
<iframe width="960" height="600"> </iframe>

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

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

iframeElem.credentialless = true;
iframeElem.title = "维基百科页面中的幽灵漏洞";
iframeElem.src = "https://zh.wikipedia.org/wiki/幽灵漏洞";

规范

Specification
Iframe credentialless
# dom-htmliframeelement-credentialless

浏览器兼容性

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
credentialless
Experimental

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.

参见