HTML DOM 프레임 / IFrame을 contentWindow 속성
정의 및 사용
contentDocument 속성은 문서에 iframe이 HTML 개체를 반환 할 수 있습니다.
처리 할 수있는 개체는 모든 표준 DOM 메소드에 의해 반환됩니다.
문법
frameObject.contentWindow
或者
iframeObject.contentWindow
或者
iframeObject.contentWindow
브라우저 지원
모든 주요 브라우저는 contentWindow 속성을 지원
예
예
다음의 예는 브라우저가 iframe이 포함 된 문서의 배경색을 변경하는 방법을 보여준다 :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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>你的浏览器不支持iframes。</p>
</iframe>
<br><br>
<input type="button" onclick="changeStyle()" value="修改背景颜色">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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>你的浏览器不支持iframes。</p>
</iframe>
<br><br>
<input type="button" onclick="changeStyle()" value="修改背景颜色">
</body>
</html>
»시도
프레임 / IFrame을 객체