HTMLIFrameElement:contentDocument 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

如果 iframe 及其父文档处于同源,则返回一个 Document(即嵌套浏览上下文中的活动文档),否则返回 null

contentDocument 示例

js
const iframeDocument = document.querySelector("iframe").contentDocument;

iframeDocument.body.style.backgroundColor = "blue";
// 这样 iframe 就会变成蓝色。

规范

Specification
HTML Standard
# dom-iframe-contentdocument

浏览器兼容性

BCD tables only load in the browser