Exforsys

JavaScript Tutorial

  1. JavaScript Browser Objects Part 2
  2. JavaScript Frame object
  3. JavaScript Form Object
  4. JavaScript FileUpload Object
  5. JavaScript Event Object Properties and Methods
  6. JavaScript Event Object
  7. JavaScript Elements and Embed Objects
  8. JavaScript Applet Objects
  9. JavaScript Browser Objects
  10. JavaScript Object Oriented Features
  11. JavaScript Window Object Open Method Part 2
  12. JavaScript Window Object Open Method
  13. JavaScript Window Object Timeout Methods
  14. JavaScript Location Object
  15. JavaScript Location Object Properties
  16. JavaScript History Object Properties and Methods
  17. JavaScript Document Object Methods Part II
  18. JavaScript Document Object Methods Part I
  19. JavaScript Document Object Properties
  20. JavaScript Document Object
  21. JavaScript Windows Object Properties Part II
  22. JavaScript Windows Object Properties Part I
  23. JavaScript DOM Window Object
  24. Working with JavaScript DOM Objects
  25. JavaScript Array Object Methods – Part II
  26. JavaScript Array Object
  27. JavaScript Array Object Methods – Part I
  28. JavaScript Boolean Object
  29. JavaScript OnError Event
  30. JavaScript Exception Handling – Part II
  31. JavaScript Exception Handling – Part I
  32. JavaScript Event Handler
  33. JavaScript Events Handling
  34. JavaScript Array Operations
  35. JavaScript Two Dimensional Arrays
  36. Passing values to JavaScript Function
  37. JavaScript Functions
  38. JavaScript Arrays
  39. JavaScript Iterative Structures - Part II
  40. JavaScript Iterative Structures - Part I
  41. JavaScript Math Object
  42. JavaScript Date Object
  43. JavaScript String Object
  44. JavaScript Objects
  45. JavaScript Confirm Box
  46. JavaScript Alert Box
  47. JavaScript Conditional Statements Part 2
  48. JavaScript Conditional Statements Part 1
  49. How to use JavaScript in HTML page
  50. JavaScript Variables
  51. JavaScript Features
  52. JavaScript Introduction

Ads


Home arrow Technical Training arrow JavaScript Tutorial

JavaScript DOM Window Object

Page 1 of 3
Author : Exforsys Inc.     Published on: 21st Jun 2007    |   Last Updated on: 10th Apr 2011

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.

Ads

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:

Ads


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.



 
This tutorial is part of a JavaScript Tutorial tutorial series. Read it from the beginning and learn yourself.

JavaScript Tutorial

  1. JavaScript Browser Objects Part 2
  2. JavaScript Frame object
  3. JavaScript Form Object
  4. JavaScript FileUpload Object
  5. JavaScript Event Object Properties and Methods
  6. JavaScript Event Object
  7. JavaScript Elements and Embed Objects
  8. JavaScript Applet Objects
  9. JavaScript Browser Objects
  10. JavaScript Object Oriented Features
  11. JavaScript Window Object Open Method Part 2
  12. JavaScript Window Object Open Method
  13. JavaScript Window Object Timeout Methods
  14. JavaScript Location Object
  15. JavaScript Location Object Properties
  16. JavaScript History Object Properties and Methods
  17. JavaScript Document Object Methods Part II
  18. JavaScript Document Object Methods Part I
  19. JavaScript Document Object Properties
  20. JavaScript Document Object
  21. JavaScript Windows Object Properties Part II
  22. JavaScript Windows Object Properties Part I
  23. JavaScript DOM Window Object
  24. Working with JavaScript DOM Objects
  25. JavaScript Array Object Methods – Part II
  26. JavaScript Array Object
  27. JavaScript Array Object Methods – Part I
  28. JavaScript Boolean Object
  29. JavaScript OnError Event
  30. JavaScript Exception Handling – Part II
  31. JavaScript Exception Handling – Part I
  32. JavaScript Event Handler
  33. JavaScript Events Handling
  34. JavaScript Array Operations
  35. JavaScript Two Dimensional Arrays
  36. Passing values to JavaScript Function
  37. JavaScript Functions
  38. JavaScript Arrays
  39. JavaScript Iterative Structures - Part II
  40. JavaScript Iterative Structures - Part I
  41. JavaScript Math Object
  42. JavaScript Date Object
  43. JavaScript String Object
  44. JavaScript Objects
  45. JavaScript Confirm Box
  46. JavaScript Alert Box
  47. JavaScript Conditional Statements Part 2
  48. JavaScript Conditional Statements Part 1
  49. How to use JavaScript in HTML page
  50. JavaScript Variables
  51. JavaScript Features
  52. JavaScript Introduction
 

Comments