IFrame contentWindow 属性
定义和用法
contentWindow
属性返回由 iframe 元素生成的 Objeto Window。
提示:通过 Objeto Window,您可以访问 Document 对象,然后访问文档的任何一个元素。
实例
例子 1
关于如何更改 iframe 中包含的文档的背景颜色的跨浏览器实例:
var x = document.getElementById("myframe"); var y = (x.contentWindow || x.contentDocument); if (y.document)y = y.document; y.body.style.backgroundColor = "red";
例子 2
如何访问 iframe 的文档以更改背景颜色的另一个例子:
var x = document.getElementById("myframe"); var y = x.contentWindow.document; y.body.style.backgroundColor = "red";
Sintaxis
iframeObject.contentWindow
Detalles técnicos
Valor de retorno: | Referencia al objeto de ventana. |
---|
Compatibilidad con navegadores
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Soporte | Soporte | Soporte | Soporte | Soporte |