Section 25.288. Window: a web browser window or frame


25.288. Window: a web browser window or frame

JavaScript 1.0: Object Global Window

25.288.1. Synopsis

 self window window.frames[i] 

25.288.2. Properties

The Window object defines the following properties and also inherits all the global properties of core JavaScript (see Global in Part III):


closed

A read-only boolean value that specifies whether the window has been closed. When a browser window closes, the Window object that represents it does not simply disappear; it continues to exist, but its closed property is set to TRue.


defaultStatus

A read/write string that specifies the default message that appears in the status line. See Window.defaultStatus.


document

A read-only reference to the Document object that describes the document contained in this window or frame (see Document for details).


event [IE only]

In Internet Explorer, this property refers to the Event object that describes the most recent event. This property is used in the IE event model. In the standard DOM event model, the Event object is passed as an argument to event-handler functions. See Event and Chapter 17 for further details.


frames[]

An array of Window objects, one for each frame or <iframe> contained within this window. The frames.length property contains the number of elements in the frames[] array. Note that frames referenced by the frames[] array may themselves contain frames and may have a frames[] array of their own.


history

A read-only reference to the History object of this window or frame. See History for details.


innerHeight, innerWidth

Read-only properties that specify the height and width, in pixels, of the document display area of this window. These dimensions do not include the size of the menu bar, toolbars, scrollbars, and so on. These properties are not supported by IE. Instead use the clientWidth and clientHeight properties of document.documentElement or document.body (depending on the version of IE). See Section 14.3.1 for details.


location

The Location object for this window or frame. This object specifies the URL of the currently loaded document. Setting this property to a new URL string causes the browser to load and display the contents of that URL. See Location for further details.


name

A string that contains the name of the window. The name is optionally specified when the window is created with the open( ) method or with the name attribute of a <frame> tag. The name of a window may be used as the value of a target attribute of an <a> or <form> tag. Using the target attribute in this way specifies that the hyperlinked document or the results of form submission should be displayed in the named window or frame.


navigator

A read-only reference to the Navigator object, which provides version and configuration information about the web browser. See Navigator for details.


opener

A read/write reference to the Window object that contained the script that called open( ) to open this browser window. This property is valid only for Window objects that represent top-level windows, not those that represent frames. The opener property is useful so that a newly created window can refer to properties and functions defined in the window that created it.


outerHeight, outerWidth

These read-only integers specify the total height and width, in pixels, of the browser window. These dimensions include the height and width of the menu bar, toolbars, scrollbars, window borders, and so on. These properties are not supported by IE, and IE offers no alternative properties.


pageXOffset, pageYOffset

Read-only integers that specify the number of pixels that the current document has been scrolled to the right (pageXOffset) and down (pageYOffset). These properties are not supported by Internet Explorer. In IE, use the scrollLeft and scrollTop properties of document.documentElement or document.body (depending on the version of IE). See Section 14.3.1 for details.


parent

A read-only reference to the Window object that contains this window or frame. If this window is a top-level window, parent refers to the window itself. If this window is a frame, the parent property refers to the window or frame that contains it.


screen

A read-only reference to a Screen object that specifies information about the screen: the number of available pixels and the number of available colors. See Screen for details.


screenLeft, screenTop, screenX, screenY

Read-only integers that specify the coordinates of the upper-left corner of the window on the screen. IE, Safari, and Opera support screenLeft and screenTop, while Firefox and Safari support screenX and screenY.


self

A read-only reference to this window itself. This is a synonym for the window property.


status

A read/write string that specifies the current contents of the browser's status line. See Window.status for details.


top

A read-only reference to the top-level window that contains this window. If this window is a top-level window itself, the top property simply contains a reference to the window itself. If this window is a frame, the top property refers to the top-level window that contains the frame. Contrast with the parent property.


window

The window property is identical to the self property; it contains a reference to this window.

25.288.3. Methods

The Window object defines the following methods, and also inherits all the global functions defined by core JavaScript (see Global in Part III).


addEventListener( )

Adds an event-handler function to the set of event handlers for this window. This method is supported by all modern browsers except IE. See attachEvent( ) for IE.


alert( )

Displays a simple message in a dialog box.


attachEvent( )

Adds an event-handler function to the set of handlers for this window. This is the IE-specific alternative to addEventListener( ).


blur( )

Takes keyboard focus away from the top-level browser window.


clearInterval( )

Cancels periodic execution of code.


clearTimeout( )

Cancels a pending timeout operation.


close( )

Closes a window.


confirm( )

Asks a yes-or-no question with a dialog box.


detachEvent( )

Removes an event-handler function from this window. This is the IE-specific alternative to removeEventListener( ).


focus( )

Gives the top-level browser window keyboard focus; this brings the window to the front on most platforms.


getComputedStyle( )

Determines the CSS styles that apply to a document element.


moveBy( )

Moves the window by a relative amount.


moveTo( )

Moves the window to an absolute position.


open( )

Creates and opens a new window.


print( )

Simulates a click on the browser's Print button.


prompt( )

Asks for simple string input with a dialog box.


removeEventListener( )

Removes an event-handler function from the set of handlers for this window. This method is implemented by all modern browsers except IE. IE provides detachEvent( ) instead.


resizeBy( )

Resizes the window by a specified amount.


resizeTo( )

Resizes the window to a specified size.


scrollBy

Scrolls the window by a specified amount.


scrollTo( )

Scrolls the window to a specified position.


setInterval( )

Executes code at periodic intervals.


setTimeout( )

Executes code after a specified amount of time elapses.

25.288.4. Event Handlers


onblur

Invoked when the window loses focus.


onerror

Invoked when a JavaScript error occurs.


onfocus

Invoked when the window gains focus.


onload

Invoked when the document (or frameset) is fully loaded.


onresize

Invoked when the window is resized.


onunload

Invoked when the browser leaves the current document or frameset.

25.288.5. Description

The Window object represents a browser window or frame. It is documented in detail in Chapter 14. In client-side JavaScript, the Window serves as the "global object," and all expressions are evaluated in the context of the current Window object. This means that no special syntax is required to refer to the current window, and you can use the properties of that window object as if they were global variables. For example, you can write document rather than window.document. Similarly, you can use the methods of the current window object as if they were functions: e.g., alert( ) instead of window.alert( ). In addition to the properties and methods listed here, the Window object also implements all the global properties and functions defined by core JavaScript. See Global in Part III for details.

The Window object has window and self properties that refer to the window object itself. You can use these to make the current window reference explicit rather than implicit. In addition to these two properties, the parent and top properties and the frames[] array refer to other Window objects related to the current one.

To refer to a frame within a window, use:

 frames[i]       // Frames of current window self.frames[i]  // Frames of current window w.frames[i]     // Frames of specified window w 

To refer to the parent window (or frame) of a frame, use:

 parent          // Parent of current window self.parent     // Parent of current window w.parent        // Parent of specified window w 

To refer to the top-level browser window from any frame contained (or nested multiple levels deep) within it, use:

 top             // Top window of current frame self.top        // Top window of current frame f.top           // Top window of specified frame f 

New top-level browser windows are created with the Window.open( ) method. When you call this method, save the return value of the open( ) call in a variable and use that variable to reference the new window. The opener property of the new window is a reference back to the window that opened it.

In general, the methods of the Window object manipulate the browser window or frame in some way. The alert( ), confirm( ), and prompt( ) methods are notable: they interact with the user through simple dialog boxes.

See Chapter 14 for an in-depth overview of the Window object, and see the individual reference pages for complete details on Window methods and event handlers.

25.288.6. See Also

Document; Global in Part III ; Chapter 14




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

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