Frame/IFrame contentWindowプロパティ

Frame/IFrame 对象参考手册Frame/IFrame オブジェクト

定義と使い方

contentWindow プロパティは、iframe 内のドキュメントを HTML オブジェクトとして返すことができます。

返されたオブジェクトは、すべての標準 DOM メソッドで処理できます。

構文

frameObject.contentWindow

または

iframeObject.contentWindow


ブラウザサポート

Internet ExplorerFirefoxOperaGoogle ChromeSafari

すべての主要ブラウザが contentWindow プロパティをサポートしています。


例

例

以下の例は、iframe に含まれるドキュメントの背景色を変更する方法をブラウザで示しています。

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>サンプル(example.com)</title> <script> function changeStyle(){ var x=document.getElementById("myframe"); var y=(x.contentWindow || x.contentDocument); if (y.document)y=y.document; y.body.style.backgroundColor="#0000ff"; } </script> </head> <body> <iframe id="myframe" src="demo_iframe.htm"> <p>お使いのブラウザはiframeをサポートしていません。</p> </iframe> <br><br> <input type="button" onclick="changeStyle()" value="背景色を変更"> </body> </html>

試してみる »


Frame/IFrame 对象参考手册Frame/IFrame オブジェクト その他の拡張