Frame/IFrame contentDocumentPropiedad
Objeto Frame/IFrame
Definición y uso
La propiedad contentDocument devuelve el documento contenido en el marco como un objeto HTML.
El objeto devuelto se puede manipular mediante todos los métodos DOM estándar.
Nota:Por razones de seguridad, el contenido del documento solo puede ser accedido por otro documento del mismo dominio.
Sintaxis
frameObject.contentDocument
o
iframeObject.contentDocument
o
iframeObject.contentDocument
Soporte del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales admiten la propiedad contentDocument.
Nota:Si se especifica !DOCTYPE, Internet Explorer 8 y versiones posteriores admiten la propiedad contentDocument; para otras versiones de IE, utilice lacontentWindowpropiedad.
Ejemplo
Ejemplo
Un ejemplo en el navegador muestra cómo modificar el color de fondo del documento dentro de un iframe:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos(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.html">
<p>Tu navegador no soporta iframes.</p>
</iframe>
<br><br>
<input type="button" onclick="changeStyle()" value="Modificar color de fondo">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos(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.html">
<p>Tu navegador no soporta iframes.</p>
</iframe>
<br><br>
<input type="button" onclick="changeStyle()" value="Modificar color de fondo">
</body>
</html>
Pruébalo »
Objeto Frame/IFrame Otras extensiones