Exforsys.com
 
Home Tutorials JavaScript
 

JavaScript DOM Window Object

 

JavaScript DOM Window Object

Page 1 of 3

JavaScript DOM Window Object

In this JavaScript tutorial, you will learn about closed property and name property, defaultStatus, status, self property of JavaScript Window object



closed Property of Window Object:

The closed property of a Window object returns a Boolean variable denoting whether window has been closed or not. The closed property tells you whether or not a window opened using window.open(). Once a window is opened in JavaScript, its closed property is immediately initialized, with a value of false. When the newly opened window is closed, then the closed property of this window is set to a value of true. A programmer can study whether a window is closed or open using the closed property of a Window object.


General syntax of closed property of Window Object:



windowname.closed



For example:


<html>
<head>
<script type="text/javascript">
function callClosed()
{
document.write("'ExforsysWindow' is closed!")
}
function callopen()
{
document.write("'ExforsysWindow' is not closed and is Open!")
}
function funcheck()
{
if (ExforsysWindow.closed)
callClosed()
else
callopen()
}
</script>
</head>
<body>
<script type="text/javascript">
ExforsysWindow=window.open('','','width=100,height=100')
ExforsysWindow.document.write("The Window is 'ExforsysWindow'")
</script>

<input type="button"
value="Is the Window 'ExforsysWindow' Closed?"
onclick="funcheck()" />
</body>
</html>



In the above example a new window object ExforsysWindow is opened using window.open statement. The opening of ExforsysWindow gives a window ExforsysWindow with message displayed as



The Window is 'ExforsysWindow'



A button is created to check whether the window object ExforsysWindow is closed or open. This is done as follows:


On the clicking of this button, the function funcheck() is called. The statement ExforsysWindow. closed is used to check whether the current state of the window ExforsysWindow is open or closed. The value returned by this statement would be false if the window is open and if the window ExforsysWindow is closed, then the value returned by this statement would be true.


If the window ExforsysWindow is closed, the value returned is true. The function callClosed() in if block is called and the statement displayed would be:



'ExforsysWindow' is closed!



If the window ExforsysWindow is open, then the value returned is false. The function callopen() in else block is called and the statement displayed would be:



'ExforsysWindow' is not closed and is Open!



name Property of Window Object:

The name property of a Window object is used for setting or returning the name of the window. The name property is a string containing the window's name.


NOTE: it is not possible to define them dynamically.


General syntax of name property of Window Object:



'ExforsysWindow' is closed!



for example


<html>
<head>
<script type="text/javascript">
function displayWindow()
{
document.write("The Name of window is: " + createdWindow.name)
}
</script>
</head>
<body>
<script type="text/javascript">
createdWindow=window.open('','Exforsys','width=100,height=100')
</script>

<input type="button"
value="What's the name of 'createdWindow'?"
onclick="displayWindow()" />
</body>
</html>



In the above example, the program first creates a window createdWindow and then a button is displayed with text as:



What's the name of 'createdWindow'



When this button is clicked, the function displayWindow() is called. Then the message and the name of the window is displayed on the screen as:




The Name of window is: Exforsys



Using the function displayWindow() creates Window.name statement in document.write statement. This creates Window.name and has the name of window as Exforsys stored in it.


Next Page: JavaScript Window Object defaultStatus Property


Read Next: JavaScript Windows Object Properties Part I



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape