Window.top

返回窗口层级最顶层窗口的引用。

语法

var topWindow = window.top;

备注

 window.parent 返回当前窗口的直接父对象,而 window.top 返回最顶层的窗口对象。

 

当你在处理父窗口的子框架(subframe),而你想获取顶层框架时,这个属性相当有用。

规范

Specification Status Comment
HTML Living Standard
window.top
Living Standard  
HTML5
window.top
Recommendation Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
topChrome Full support 1Edge Full support 12Firefox Full support 1
Notes
Full support 1
Notes
Notes Starting in Firefox 6, this property is read only, as defined by the standard.
IE Full support 4Opera Full support ≤12.1Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support ≤12.1Safari iOS Full support 1Samsung Internet Android Full support 1.0

Legend

Full support  
Full support
See implementation notes.
See implementation notes.