HTMLIFrameElement: sandbox 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

HTMLIFrameElement 介面的只讀屬性 sandbox 返回一個 DOMTokenList,指示對巢狀內容的行為附加的限制。

它反映了 <iframe> 元素的 sandbox 屬性。

一個 DOMTokenList。每個專案必須是 <iframe> 元素的 sandbox 屬性中列出的 token 之一。

示例

html
<iframe
  id="el"
  title="example"
  src="https://example.com"
  sandbox="allow-same-origin allow-scripts"></iframe>
js
const el = document.getElementById("el");
console.log(Array.from(el.sandbox)); // Output: ["allow-same-origin", "allow-scripts"]

el.sandbox = "";
console.log(Array.from(el.sandbox)); // Output: []

規範

規範
HTML
# dom-iframe-sandbox

瀏覽器相容性