HTMLIFrameElement.contentWindow

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.

Example of contentWindow

var iframe = document.getElementsByTagName("iframe")[0];
var x = iframe.contentWindow;
if (x.document) {
    x = iframe.document; 
    // to ensure compability
} 
x.body.style.backgroundColor = "blue";
// this would turn the iframe blue.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

Document Tags and Contributors

 Contributors to this page: bantya, cPhost, Tigt, eharris, teoli, liferunsoncode
 Last updated by: bantya,