Difference between revisions of "JavaScript Window Object"

From Techotopia
Jump to: navigation, search
(Referencing the JavaScript window Object)
(JavaScript window Object Properties)
Line 17: Line 17:
  
 
== JavaScript window Object Properties ==
 
== JavaScript window Object Properties ==
 +
 +
The JavaScript window object contains a number of properties that can be inspected and used in a script:
 +
 +
* '''window.closed''' - Used when handling multiple windows, this property indicates whether a window has been closed or not.
 +
 +
* '''window.defaultstatus / window.status''' - ''defaultstatus'' specifies the default message displayed in the browser status bar. ''status'' specifies a temporary message to display in the browser status bar in place of the default. Disabled in many browsers.
 +
 +
* '''window.frames[]''' - If the window contains frames this array holds the arrary of frame objects (see [[JavaScript Arrays]] details on accessing arrays).
  
 
== Opening and Closing Browser Windows ==
 
== Opening and Closing Browser Windows ==

Revision as of 17:15, 9 May 2007

The JavaScript window object sits at the top of the JavaScript Object hierarchy and represents the browser window (or windows if you have more than one browser window open at any one time). Up until this chapter we have focused on the internals and syntax of JavaScript. In this chapter we will begin to make things happen on the screen (which, after all, is one of the main purposes of JavaScript). The window object allows developers to perform tasks such as opening and closing browser windows, displaying alert and prompt dialogs and set up timeouts (specifying an action to take place after a specified period of time).

Referencing the JavaScript window Object

As covered in JavaScript Object Basics it is usually necessary to use dot-notation when accessing properties or methods of an object. For example the following script fragment accesses the write() method of the document object:

document.write("Hello");

The window object is the top-level object of the object hierarchy. As such, whenever an object method or property is referenced in a script without the object name and dot prefix it is assumed by JavaScript to be a member of the window object. This means, for example, that when calling the window alert() method to display an alert dialog the window. prefix is not mandatory. Therefore the following method calls achieve the same thing:

window.alert();
alert()

JavaScript window Object Properties

The JavaScript window object contains a number of properties that can be inspected and used in a script:

  • window.closed - Used when handling multiple windows, this property indicates whether a window has been closed or not.
  • window.defaultstatus / window.status - defaultstatus specifies the default message displayed in the browser status bar. status specifies a temporary message to display in the browser status bar in place of the default. Disabled in many browsers.
  • window.frames[] - If the window contains frames this array holds the arrary of frame objects (see JavaScript Arrays details on accessing arrays).

Opening and Closing Browser Windows