Cadre HTML DOM / propriété IFrame contentWindow
Définition et utilisation
propriété contentDocument peut retourner objet HTML iframe au document.
Peut gérer les objets sont retournés par toutes les méthodes DOM standard.
grammaire
frameObject.contentWindow
或者
iframeObject.contentWindow
或者
iframeObject.contentWindow
support du navigateur
Tous les principaux navigateurs prennent en charge la propriété contentWindow
Exemples
Exemples
L'exemple suivant montre comment un navigateur pour changer la couleur du document contenant l'iframe de fond:
<!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>
Essayez »
Structure / objets iFrame