JavaScript » Objects » Window

As the top level object in the JavaScript client hierarchy, every browser window and frame has a corresponding Window object, created automatically with every instance of a <BODY> or <FRAMESET> tag.

Properties

closed

Syntax: window.closed

This property is used to return a Boolean value that determines if a window has been closed. If it has, the value returned is true.

constructor

Syntax: Object.constructor

This specifies a function to create an object's property and is inherited by all objects from their prototype.

defaultStatus

Syntax: window.defaultStatus( = "message")

This property is used to define the default message displayed in a window's status bar.

document

Syntax: window.document

This property's value is the document object contained within the window. See Document object.

frames

Syntax: window.frames("frameID")

This property is an array containing references to all the named child frames in the current window.

history

This property's value is the window's History object, containing details of the URL's visited from within that window. See History object.

location

Syntax: window.location

This property contains details of the current URL of the window and its value is always the Location object for that window.

locationbar

Syntax: window.locationbar[.visible = false]

This property relates to the area of a browser's window that contains the details of the URL or bookmark (this is where you physically enter URL details). The locationbar property has its own property, visible, that defaults to true (visible) and can be set to false (hidden).

menubar

Syntax: window.menubar[.visible = false]

This property relates to the area of a browser's window that contains the various pull-down menus (File, Edit, View, etc.). The menubar property has its own property, visible, that defaults to true (visible) and can be set to false (hidden).

name

Syntax: window.name

This property is used to return or set a window's name.

opener

Syntax: window.opener

When opening a window using window.open, use this property from the destination window to return details of the source window. This has many uses, for example, window.opener.close() will close the source window.

outerheight

Syntax: window.outerheight

These properties determine the dimensions, in pixels, of the outside boundary, including all interface elements, of a window.

outerwidth

Syntax: window.outerwidth

pageXOffset

Syntax: window.pageXOffset

These properties return the X and Y position of the current page in relation to the upper left corner of a window's display area.

pageYOffset

Syntax: window.pageYOffset

These properties return the X and Y position of the current page in relation to the upper left corner of a window's display area.

parent

Syntax: window.parent

This property is a reference to the window or frame that contains the calling child frame.

personalbar

Syntax: window.personalbar[.visible = false]

This property relates to the browser's personal bar (or directories bar). The personalbar property has its own property, visible, that defaults to true (visible) and can be set to false (hidden).

prototype

Syntax: Object.prototype.name = value

This allows the addition of properties and methods to any object.

scrollbars

Syntax: window.scrollbars[.visible = false]

This property relates to the browser's scrollbars (vertical and horizontal). The scrollbars property has its own property, visible, that defaults to true (visible) and can be set to false (hidden).

self

Syntax: self.property or method

This property is a reference (or synonym) for the current active window or frame.

status

Syntax: window.status= ( "message")

This property, which can be set at any time, is used to define the transient message displayed in a window's status bar such as the text displayed when you onMouseOver a link or anchor.

statusbar

Syntax: window.statusbar[.visible = false]

This property relates to the browser's status bar. The statusbar property has its own property, visible, that defaults to true (visible) and can be set to false (hidden).

toolbar

Syntax: window.toolbar[.visible = false]

This property sets or returns a Boolean value that defines whether the browser's tool bar is visible or not. The default is true (visible). False means hidden. It can only be set before the window is opened and you must have UniversalBrowserWrite privilege.

top

Syntax: top.property or method

This property is a reference (or synonym) for the topmost browser window.

window

Syntax: window.property or method

This property is a reference (or synonym) for the current window or frame.

Methods

alert

Syntax: window.alert("message")

This method displays an alert box containing a message and an o.k. button.

back

Syntax: window.back()

Using this method is the same as clicking the browser's Back button, i.e. it undoes the last navigation step performed from the current top-level window.

blur

Syntax: window.blur( )

This method is used to remove focus from the current window.

captureEvents

Syntax: window.captureEvent(eventType)

This method instructs the window to capture all events of a particular type. See the event object for a list of event types.

clearInterval

Syntax: window.clearInterval(intervalID)

This method is used to cancel a timeout previously set with the setInterval method.

clearTimeout

Syntax: window.clearTimeout(timeoutID)

This method is used to cancel a timeout previously set with the setTimeout method.

close

Syntax: window.close( )

This method is used to close a specified window. If no window reference is supplied, the close() method will close the current active window. Note that this method will only close windows created using the open() method; if you attempt to close a window not created using open(), the user will be prompted to confirm this action with a dialog box before closing. The single exception to this is if the current active window has only one document in its session history. In this case the closing of the window will not require confirmation.

confirm

Syntax: confirm("message")

This method brings up a dialog box that prompts the user to select either 'o.k.' or 'cancel', the first returning true and the latter, false.

disableExternalCapture

Syntax: window.disableExternalCapture( )

This method disables the capturing of events previously enabled using the enableExternalCapture method below.

enableExternalCapture

Syntax: window.enableExternalCapture( )

This method allows a window that contains frames to capture events in documents loaded from different servers.

eval

Syntax: Object.eval(string)

The eval method is deprecated as a method of Object, but is still used as a high level function. It evaluates a string of JavaScript in the context of an object.

find

Syntax: window.find([string[, caseSensitive, backward]])

This method allows the searching of the contents of a window for a specified string. The caseSensitive and backward arguments are Booleans and to use either of these you must also specify the other. If a search string is not supplied, JavaScript will display a Find dialog box which prompts the user for a string to search for, and also provides the facility to set the other two (caseSensitive and backward) arguments.

focus

Syntax: window.focus( )

This method is used to give focus to the specified window. This is useful for bringing windows to the top of any others on the screen.

forward

Syntax: window.forward()

Using this method is the same as clicking the browser's Forward button, i.e. it goes to the next URL in the history list of the current top-level window.

handleEvent

Syntax: window.handleEvent("eventID")

This method is used to call the handler for the specified event.

home

Syntax: window.home( )

Using this method has the same effect as pressing the Home button in the browser, i.e. the browser goes to the URL set by the user as their home page.

moveBy

Syntax: window.moveBy(horizPixels, vertPixels)

This method is used to move the window a specified number of pixels in relation to its current co-ordinates.

moveTo

Syntax: window.moveTo(Xposition, Yposition)

This method moves the window's left edge and top edge to the specified x and y co-ordinates, respectively.

open

Syntax: window.open(URL, name [, features])

This method is used to open a new browser window.

print

Syntax: window.print( )

This method is used to print the contents of the specified window.

prompt

Syntax: window.prompt(message[, defaultInput])

This method displays a dialog box prompting the user for some input.

releaseEvents

Syntax: window.releaseEvents("eventType")

This method is used to release any captured events of the specified type and to send them on to objects further down the event hierarchy

resizeBy

Syntax: window.resizeBy(horizPixels, vertPixels)

This method is used to resize the window. It moves the bottom right corner of the window by the specified horizontal and vertical number of pixels while leaving the top left corner anchored to its original co-ordinates.

resizeTo

Syntax: window.resizeTo(outerWidth, outerHeight)

This method is used to resize a window to the dimensions supplied with the outerWidth and outerHeight (both integers, in pixels) parameters.

routeEvent

Syntax: window.routeEvent(eventType)

This method is used to send a captured event further down the normal event hierarchy; specifically, the event is passed to the original target object unless a sub-object of the window (a document or layer) is also set to capture this type of event, in which case the event is passed to that sub-object.

scroll

Syntax: window.scroll(coordsPixels)

This method is used to scroll the window to the supplied co-ordinates. This method is now deprecated; use the scrollTo method detailed below instead.

scrollBy

Syntax: window.scrollBy(horizPixels, vertPixels)

This method is used to scroll the window's content area by the specified number of pixels. This is only useful when there are areas of the document that cannot be seen within the window's current viewing area, and the visible property of the window's scrollbar must be set to true for this method to work.

scrollTo

Syntax: window.scrollTo(xPosition, yPosition)

This method scrolls the contents of a window, the specified co-ordinate becoming the top left corner of the viewable area.

setInterval

Syntax: window.setInterval(expression/function, milliseconds)

This method is used to call a function or evaluate an expression at specified intervals, in milliseconds.

setTimeout

Syntax: [intervalID =] window.setTimeout(expression/function, milliseconds)

This method is used to call a function or evaluate an expression after a specified number of milliseconds.

stop

Syntax: window.stop( )

This method is used to cancel the current download. This is the same as clicking the browser's Stop button.

toSource

Syntax: Object.toSource()

The toSource method returns a literal representing the source code of an object. This can then be used to create a new object.

toString

Syntax: Object.toString()

The toString method returns a string representing a specified object.

unwatch

Syntax: Object.unwatch(property)

This method removes a watchpoint set for an object and property name with the watch method.

valueOf

Syntax: Object.valueOf()

This method returns a primitive value for a specified object.

watch

Syntax: Object.watch(property, handlerfunction)

This method adds a watchpoint to a property of the object.

See Also: