HTMLIFrameElement: contentWindow property
The contentWindow
property returns the Window object of an HTMLIFrameElement. 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.
Value
A Window object.
Examples
js
const x = document.querySelector("iframe").contentWindow;
//x = window.frames[0];
x.document.querySelector("body").style.backgroundColor = "blue";
// this would turn the 1st iframe in document blue.
Specifications
Specification |
---|
HTML Standard # dom-iframe-contentwindow |
Browser compatibility
BCD tables only load in the browser