HTMLIFrameElement: credentialless 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

HTMLIFrameElement 介面的 credentialless 屬性指示 <iframe> 是否是 "credentialless"(無憑證)的,這意味著其中的文件將使用新的、臨時的上下文載入。

這些上下文無法訪問與其來源關聯的網路、Cookie 和儲存資料。相反,它們使用新的、僅限於頂層文件生命週期的上下文。這意味著在使用者離開頁面或重新載入頁面後,任何儲存的資料將不再可訪問。

作為回報,可以放寬 Cross-Origin-Embedder-Policy (COEP) 嵌入規則,因此設定了 COEP 的文件可以嵌入未設定 COEP 的第三方文件。有關更深入的解釋,請參閱 IFrame credentialless

一個布林值。預設值為 false;將其設定為 true 以使 <iframe> 成為 credentialless。

示例

獲取

如下指定一個 credentialless <iframe>

html
<iframe
  src="https://en.wikipedia.org/wiki/Spectre_(security_vulnerability)"
  title="Spectre vulnerability Wikipedia page"
  width="960"
  height="600"
  credentialless></iframe>

返回 credentialless 屬性的值

js
const iframeElem = document.querySelector("iframe");
console.log(iframeElem.credentialless); // will return true in supporting browsers

Set

或者,在 HTML 中指定最少細節

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

然後將 credentialless 設定為 true,再透過指令碼載入 <iframe> 內容

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

iframeElem.credentialless = true;
iframeElem.title = "Spectre vulnerability Wikipedia page";
iframeElem.src =
  "https://en.wikipedia.org/wiki/Spectre_(security_vulnerability)";

規範

規範
Iframe credentialless
# dom-htmliframeelement-credentialless

瀏覽器相容性

另見