HTML DOM Rama / nieruchomość IFrame contentDocument
Definicja i Wykorzystanie
Obiekt contentDocument aby pomieścić HTML powrócił dokument ramowy obiektu.
Może obsługiwać obiekty są zwracane przez wszystkich standardowych metod DOM.
Uwaga: Ze względów bezpieczeństwa, treść dokumentu można uzyskać tylko przez inny dokument pod tą samą nazwą domeny.
gramatyka
frameObject.contentDocument
或者
iframeObject.contentDocument
或者
iframeObject.contentDocument
Pomoc Browser
Wszystkie główne przeglądarki obsługują właściwość contentDocument
!Uwaga: W przypadku określenia DOCTYPE, Internet Explorer 8 i nowsze obsługują właściwość contentDocument, należy użyć innej wersji IE contentWindow nieruchomości.
Przykłady
Przykłady
Przykładem przeglądarka pokazuje jak zmienić kolor tła dokumentu 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>
Spróbuj »
Rama / obiekty iframe