HTMLIFrameElement.contentWindow

contentWindow属性返回<iframe>元素的Window对象。你可以使用这个Window对象来访问iframe的文档及其内部DOM。contentWindow为只读,但是可以像操作全局Window对象一样操作其属性。

Example of contentWindow

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.

Specifications

Specification Status Comment
HTML Living Standard
HTMLIFrameElement: contentWindow
Living Standard  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
contentWindowChrome Full support 43Edge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support 6WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, xgqfrms, kameii, Marcia_gm
最后编辑者: mdnwebdocs-bot,