The contentWindow
property returns the Window object of an <iframe> element. You can use this Window
object to access the iframe's document and its internal DOM. This attribute is read-only, but its properties can be manipulated like the global Window
object.
var x = document.getElementsByTagName("iframe")[0].contentWindow; //x = window.frames[0]; x.document.getElementsByTagName("body")[0].style.backgroundColor = "blue"; // this would turn the 1st iframe in document blue.
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'HTMLIFrameElement: contentWindow' in that specification. | Living Standard |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 43 | Yes | Yes | Yes | Yes | 6 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | Yes | Yes | Yes | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/contentWindow