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

浏览器兼容性