The top
property returns the topmost browser window of the current window.
top |
Yes | Yes | Yes | Yes | Yes |
var v = window.top
A reference to the topmost window in the window hierarchy.
<!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: