Javascript Reference - Window top Property








The top property returns the topmost browser window of the current window.

Browser Support

top Yes Yes Yes Yes Yes

Syntax

var v = window.top

Return Value

A reference to the topmost window in the window hierarchy.





Example


<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {<!--  w  ww.j a  v a  2s. c om-->
    if (window.top!=window.self)  {
        console.log("This window is not the topmost window!");
    } else { 
        console.log("This window is the topmost window!");
    } 
}
</script>
</head>
<body>

<button onclick="myFunction()">Check window</button>
</body>
</html>

The code above is rendered as follows: