Window top 属性

定义和用法

top 属性返回当前浏览器窗口中最顶层的窗口。

top 属性是只读的。

提示

top 属性与 parent 属性不同。

window.top 返回窗口层次结构中最顶层的窗口。

window.parent 返回窗口的直接父级。

另请参阅:

parent 属性

实例

这个窗口是最上面的窗口吗:

if (window.top != window.self) {
  text = "This window is NOT the topmost window!";
} else {
  text = "This window is the topmost window!";
}

亲自试一试

Syntax

window.top

Return Value

Type Description
Object. The top-level window in the window hierarchy of the current browser window.

Browser Support

All Browsers Support window.top:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support