Properties of the window Object


Properties of the window Object

As we know, the window object is the big cheese of browser objects, corresponding to the browser window and containing, among other objects, the document , location , and history objects. Those objects are available through properties of the same name in the window object; for example, we've already seen how to navigate the browser to a URL the user types using the loca tion objectwhich is part of the window objectlike this (this is Listing 04-06.html on the web sitemore on the location object in Chapter 10, "Using the navigator , location , and history Objects"):

 <HTML>      <HEAD>          <TITLE>              Navigate to an URL          </TITLE>          <SCRIPT LANGUAGE = "JavaScript">              <!--             function Jump()              {  window.location.href = document.form1.text1.value  }              // -->          </SCRIPT>      </HEAD>      <BODY>          <H1>Navigate to an URL</H1>          <FORM NAME = "form1">              <BR>              <INPUT TYPE = TEXT NAME="text1" SIZE = 80>              <BR>              <BR>              <INPUT TYPE = BUTTON Value="Navigate to URL" ONCLICK="Jump()">          </FORM>      </BODY>  </HTML> 

Tip

Because the window object is the overall containing object in a browser, you can usually omit referring to it when using its properties, events, and methods if there's no possibility of confusion. For example, I could have written window.location.href = document.form1.text1.value above as location.href = document.form1.text1.value .


You can find an overview of the properties of the window object in Table 7.1 (note that not all properties apply to all browsers), and property-by-property coverage in Table 7.2. In this chapter, we'll discuss those properties.

Table 7.1. Overview of the Properties of the window Object

Properties

     

appCore

clientInformation

clipboardData

closed

Components

controllers

crypto

defaultStatus

dialogArguments

dialogHeight

dialogLeft

dialogTop

dialogWidth

directories

document

event

external

frameElement

frames

history

innerHeight

innerWidth

length

loading

location

locationbar

menubar

name

navigator

offscreenBuffering

opener

outerHeight

outerWidth

pageXOffset

pageYOffset

parent

personalbar

pkcs11

prompter

returnValue

screen

screenLeft

screenTop

screenX

screenY

scrollbars

scrollX

scrollY

self

sidebar

status

statusbar

toolbar

top

window

 
Table 7.2. The Properties of the window Object

Property

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

appCore

     

x

           
 

Read-only

 

This property is a Netscape 6.0 property that allows scripting access (called XPConnect) to COM objects and Netscape's XML-based XUL objects. See www.mozilla.org/scriptable/ for the details.

clientInformation

           

x

x

x

x

 

Read-only

 

Another name for the navigator object in the Internet Explorer.

clipboardData

             

x

x

x

 

Read/write

 

Allows access to the clipboard. See "Using the Clipboard" in this chapter for the details, as well as "The oncopy Event" in Chapter 6, "Using Core HTML Methods and Events."

closed

 

x

x

x

     

x

x

x

 

Read-only

 

Set to true if a window object has been closed, and false otherwise . Useful if you're handling multiple window objects at the same time. See "Working with New Windows " in this chapter for an example.

Components

     

x

           
 

Read-only

 

This property is a Netscape 6.0 property that allows scripting access (Called XPConnect) to COM objects and Netscape's XML-based XUL objects. See www.mozilla.org/scriptable/ for the details.

controllers

     

x

           
 

Read-only

 

This property is a Netscape 6.0 property that allows scripting access (Called XPConnect) to COM objects and Netscape's XML-based XUL objects. See www.mozilla.org/scriptable/ for the details.

crypto

     

x

           
 

Read-only

 

This property is used in Netscape's public-key cryptography efforts; for more details, see www.mozilla.org/projects/security.

defaultStatus

x

x

x

x

x

x

x

x

x

x

 

Read/write

 

Holds the default text for the status bar (visible when the page first loads). If the mouse moves over a link, the default text will be replaced temporarily and restored when the mouse leaves the link. See "Accessing the Status Bar" in this chapter for an example.

dialogArguments

           

x

x

x

x

 

Read-only

 

Holds arguments passed to dialog boxes (used to initialize the dialog boxes), which are windows opened with the Internet Explorer methods showModalDialog and showModelessDialog . See "Creating Dialog Boxes" in this chapter for an example. More on the showModalDialog and showModelessDialog methods in Chapter 8, "Using window and frame Methods and Events."

dialogHeight

           

x

x

x

x

 

Read/write

 

Sets or gets the height of dialog boxes, which are windows opened with the Internet Explorer methods showModalDialog and showModelessDialog . See "Creating Dialog Boxes" in this chapter for an example. More on the showModalDialog and showModelessDialog methods in Chapter 8.Values include "px" to indicate pixel measurements, like this: "300px" .

dialogLeft

           

x

x

x

x

 

Read/write

 

Sets the left position of dialog boxes, which are windows opened with the Internet Explorer methods showModalDialog and showModelessDialog . See "Creating Dialog Boxes" in this chapter for an example. More on the showModalDialog and showModelessDialog methods in Chapter 8.Values include "px" to indicate pixel measurements, like this: "300px" .

dialogTop

           

x

x

x

x

 

Read/write

 

Sets the top position of dialog boxes, which are windows opened with the Internet Explorer methods showModalDialog and showModelessDialog . See "Creating Dialog Boxes" in this chapter for an example. More on the showModalDialog and showModelessDialog methods in Chapter 8.Values include "px" to indicate pixel measurements, like this: "300px" .

dialogWidth

           

x

x

x

x

 

Read/write

 

Sets the width of dialog boxes, which are windows opened with the Internet Explorer methods showModalDialog and showModelessDialog . See "Creating Dialog Boxes" in this chapter for an example. More on the showModalDialog and showModelessDialog methods in Chapter 8. Values include "px" to indicate pixel measurements, like this: "300px" .

directories

   

x

x

           
 

Read/write

 

One of the properties that enables you to customize the appearance of the Netscape Navigator by displaying or hiding menu bars, location bars, and so on. See "Displaying and Hiding Netscape Navigator Bars" in this chapter.

document

x

x

x

x

x

x

x

x

x

x

 

Read-only

 

The document object. See Chapter 9, "Using the document and body Objects," for the details.

event

           

x

x

x

x

 

Read/write

 

The global event object in the Internet Explorer, holding data about events that have occurred. See Chapter 6 for the details.

external

           

x

x

x

x

 

Read-only

 

This property gives you access to a host application when the Internet Explorer is being run from such an application. This property corresponds to the external object, which includes methods such as AddDesktopComponent(URL, Type [, Left] [, Top] [, Width] [, Height]) to add a desktop component (set Type to "website" or

 

"image" , and AddFavorite(URL [, Title]) , which adds an URL to the Internet Explorer's favorites list; here's an example showing how to use AddFavorite: window.external.AddFavorite(location.href, document.title) .

frameElement

               

x

x

 

Read-only

 

If a window is being displayed in a frame, this property returns the parent <FRAME> or <IFRAME> element.

frames

x

x

x

x

x

x

x

x

x

x

 

Read-only

 

Holds an array of frames contained by a window. See "Using Frame Properties" in this chapter for an example.

history

x

x

x

x

x

x

x

x

x

x

 

Read-only

 

The history object, which holds the browser's past locations. See Chapter 10 for the details.

innerHeight

   

x

x

           
 

Read/write

 

Holds the height of the client area of the browser (where the document is displayed). The Netscape Navigator enables you to change this property on-the-fly . See "Setting the Netscape Navigator's Dimensions" in this chapter for an example.

innerWidth

   

x

x

           
 

Read/write

 

Holds the width of the client area of the browser (where the document is displayed). The Netscape Navigator enables you to change this property on-the-fly. See "Setting the Netscape Navigator's Dimensions" in this chapter for an example.

length

A JavaScript HTML core property. See Chapter 5, "Using Core HTML Properties."

loading

   

x

             
 

Read-only

 

Returns true if a window is still being loaded, and false otherwise. Specific to Netscape Navigator 4.0 only!

location

x

x

x

x

x

x

x

x

x

x

 

Read/write

 

The location object. See Chapter 10 for the details.

locationbar

   

x

x

           
 

Read/write

 

One of the properties that enables you to customize the appearance of the Netscape Navigator by displaying or hiding menu bars, location bars, and so on. See "Displaying and Hiding Netscape Navigator Bars" in this chapter for an example.

menubar

   

x

x

           
 

Read/write

 

One of the properties that enables you to customize the appearance of the Netscape Navigator by displaying or hiding menu bars, location bars, and so on. See "Displaying and Hiding Netscape Navigator Bars" in this chapter for an example.

name

x

x

x

x

x

x

x

x

x

x

 

Read/write

 

A window's name. By default, a top-level window has no name, although you can supply one with the window.name property. Windows are often given names in <FRAMESET> elements; see "Using Frame Properties" in this chapter for an example.

navigator

     

x

   

x

x

x

x

 

Read-only

 

The navigator object. See Chapter 10.

offscreenBuffering

           

x

x

x

x

 

Read/write

 

Specifies whether the Internet Explorer draws a page in memory before displaying it on the screen. A page saved in memory can be presented immediately to the user (that is, the user won't have to watch the page being constructed piece-by-piece on the screen). The default value here is auto , which lets the Internet Explorer decide when to use offscreen buffering. You can turn on offscreen buffering by setting this value to true, or turn it off by setting it to false.

opener

 

x

x

x

x

x

x

x

x

x

 

Read-only

 

The window that opened the current window. This property gives you access to a parent window; see "Working with New Windows" in this chapter for an example.

outerHeight

   

x

x

           
 

Read/write

 

Holds the height of the browser itself. The Netscape Navigator enables you to change this property on-the-fly. See "Setting the Netscape Navigator's Dimensions" in this chapter for an example.

outerWidth

   

x

x

           
 

Read/write

 

Holds the width of the browser itself. The Netscape Navigator enables you to change this property on-the-fly. See "Setting the Netscape Navigator's Dimensions" in this chapter for an example.

pageXOffset

   

x

x

           
 

Read-only

 

The X coordinate (in document coordinates) of the top left of the client area (the area where the document is displayed) when the document has been scrolled.

pageYOffset

   

x

x

           
 

Read-only

 

The Y coordinate (in document coordinates) of the top left of the client area (the area where the document is displayed) when the document has been scrolled.

parent

x

x

x

x

x

x

x

x

x

x

 

Read-only

 

Usually used when you're working with windows in frames. This property corresponds to the window's parent window object. See "Using Frame Properties" in this chapter for an example.

personalbar

   

x

x

           
 

Read/write

 

One of the properties that enables you to customize the appearance of the Netscape Navigator by displaying or hiding menu bars, location bars, and so on. See "Displaying and Hiding Netscape Navigator Bars" in this chapter for an example.

pkcs11

     

x

           
 

Read-only

 

This property is used in Netscape's public-key cryptography efforts; for more details, see www.mozilla.org/projects/security.

prompter

     

x

           
 

Read-only

 

This property is a Netscape 6.0 property that allows scripting access (called XPConnect) to COM objects and Netscape's XML-based XUL objects. See www.mozilla.org/scriptable/ for the details.

returnValue

           

x

x

x

x

 

Read/write

 

Holds the return value from dialog boxes, which are windows opened with the Internet Explorer methods showModalDialog and showModelessDialog . This return value can be an array of values set by the user in the dialog box. See "Creating Dialog Boxes" in this chapter for an example.

screen

     

x

   

x

x

x

x

 

Read-only

 

The screen object, which holds data about the screen, such as its dimensions. See "The screen Object" in this chapter for an example.

screenLeft

             

x

x

x

 

Read-only

 

Holds the left position of the client area (the area where the document is displayed, excluding toolbars , menu bars, and so on) with respect to the top left of the screen (which is treated as (0, 0)). Measured in pixels.

screenTop

             

x

x

x

 

Read-only

 

Holds the top of the client area (the area where the document is displayed, excluding toolbars, menu bars, and so on) with respect to the upper-left corner of the screen (which is treated as (0, 0)). Measured in pixels.

screenX

     

x

           
 

Read/write

 

Holds the X position of the left edge of the browser in screen coordinates (where the upper left corner of the screen is (0, 0)). Measured in pixels.

screenY

     

x

           
 

Read/write

 

Holds the Y position of the top edge of the browser in screen coordinates (where the upper-left corner of the screen is (0, 0)). Measured in pixels.

scrollbars

   

x

x

           
 

Read/write

 

One of the properties that enables you to customize the appearance of the Netscape Navigator by displaying or hiding menu bars, location bars, and so on. See "Displaying and Hiding Netscape Navigator Bars" in this chapter for an example.

scrollX

     

x

           
 

Read-only

 

Holds the horizontal position of a scrolled window. Measured in pixels.

scrollY

     

x

           
 

Read-only

 

Holds the vertical position of a scrolled window. Measured in pixels.

self

x

x

x

x

x

x

x

x

x

x

 

Read-only

 

Refers to the current window (just like using the window object for the current window).

sidebar

     

x

           
 

Read-only

 

This property is a Netscape 6.0 property that allows scripting access (called XPConnect) to COM objects and Netscape's XML-based XUL objects. See www.mozilla.org/scriptable/ for the details.

status

x

x

x

x

x

x

x

x

x

x

 

Read/write

 

Holds the text displayed in the browser's status bar. See "Accessing the Status Bar" in this chapter for an example.

statusbar

   

x

x

           
 

Read/write

 

One of the properties that enables you to customize the appearance of the Netscape Navigator by displaying or hiding menu bars, location bars, and so on. See "Displaying and Hiding Netscape Navigator Bars" in this chapter for an example.

toolbar

   

x

x

           
 

Read/write

 

One of the properties that enables you to customize the appearance of the Netscape Navigator by displaying or hiding menu bars, location bars, and so on. See "Displaying and Hiding Netscape Navigator Bars" in this chapter for an example.

top

x

x

x

x

x

x

x

x

x

x

 

Read-only

 

Refers to the top window in a window hierarchy. When you are using frames, for example, top refers to the topmost containing window. See "Using Frame Properties" in this chapter for an example.

window

x

x

x

x

x

x

x

x

x

x

 

Read-only

 

The same as the window object itself, even though this is a property of the window object. (There's no real reason to use this property.)

As you can see in Table 7.2, the window object has a great many properties. Let's put them to work.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net