このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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 ⁨2015年7月⁩.

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

ブラウザーの互換性