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
# dom-iframe-contentdocument

浏览器兼容性

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
contentDocument

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support