HTMLIFrameElement: contentWindow プロパティ

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.

contentWindow プロパティは、HTMLIFrameElement が所属する Window オブジェクトを返します。この Window オブジェクトを使用して、iframe の文書や内部 DOM にアクセスすることができます。この属性は読み取り専用ですが、グローバルの Window オブジェクトのように操作することができます。

Window オブジェクト。

js
const x = document.querySelector("iframe").contentWindow;
//x = window.frames[0];

x.document.querySelector("body").style.backgroundColor = "blue";
// 文書内の最初の iframe が青くなる

仕様書

Specification
HTML
# dom-iframe-contentwindow

ブラウザーの互換性

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
contentWindow

Legend

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

Full support
Full support