HTMLIFrameElement: contentWindow プロパティ
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 Standard # dom-iframe-contentwindow |
ブラウザーの互換性
BCD tables only load in the browser