Javascript Reference - Window self Property








The self property returns the current window.

Browser Support

self Yes Yes Yes Yes Yes

Syntax

window.self

Return Value

A reference to the window object itself.

Example


<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {<!--from   ww  w .  ja  va 2  s .  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: