Window topProperty
Window Object
Definition and Usage
The top property returns the topmost browser window of the current window.
Syntax
window.top
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the top property.
Example
Example
When the "Check window" button is clicked, check() is called and checks the state of the current window:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function check(){
if (window.top!=window.self) {
document.write("<p>This window is not the topmost window! Am I in a frame?</p>")
}
else{
document.write("<p>This window is the topmost window!</p>")
}
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="Check window">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function check(){
if (window.top!=window.self) {
document.write("<p>This window is not the topmost window! Am I in a frame?</p>")
}
else{
document.write("<p>This window is the topmost window!</p>")
}
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="Check window">
</body>
</html>
Try it Yourself »
Window Object Other Extensions