Tutorials
JavaScript
JavaScript DOM Window Object
JavaScript Window Object defaultStatus Property
JavaScript Window Object Self PropertyThe self property of the Window object refers to the current window and returns a reference to the current window.
General syntax of self property of Window Object:
window.self
An example to understand this concept:
<html>
<head>
<script type="text/javascript">
function checkwindow()
{
if (window.top!=window.self)
{
document.write("The window is not current
window!!!!!")
}
else
{
document.write("The window is current window!!!!!")
}
}
</script>
</head>
<body>
<input type="button" onclick="checkwindow()"
value="Check the Window by clicking Here">
</body>
</html>
In the above example a button is displayed with message
Check the Window by clicking Here
When this button is clicked, the function checkwindow() is called and the Current Window status is checked. If the Window top is equal to window.self (which has the reference to the current window) then else statement gets fired and the message:
The window is current window!!!!!
is displayed.
If the Window top is not equal to window.self (which has the reference to the current window) then if statement gets fired and the message:
The window is not current window!!!!!
is displayed.
First Page: JavaScript DOM Window Object