Window : Object

The Window object represents the web browser window. It provides access to objects to use to manipulate the browsing environment and properties for accessing the object model below it.

Browser/User Agent Support

IEMozillaNetscapeOperaSafari
3.0+1.0+2.0+7.0+1.0+

Constructors

ConstructorIEMozillaNetscapeOperaSafari
Creates a new instance of a Window object.
3.0+1.0+2.0+7.0+1.0+
 

Properties

PropertyIEMozillaNetscapeOperaSafari
Gets or sets the default text in the status bar at the bottom of a web browser window.
3.0+1.0+2.0+7.0+1.0+
 
Gets or sets the name of a window.
3.0+1.0+2.0+7.0+1.0+
 
Fires when the loading of the element is cancelled before it finishes loading.
4.0+nonono1.0+
 
Fires immediately after a user prints or print previews a document.
4.0+nononono
 
Fires immediately before a user prints or print previews a document.
4.0+nononono
 
Fires immediately before a document is unloaded.
4.0+nononono
 
Event handler for blur events on a window.
3.0+1.0+2.0+7.0+1.0+
 
Fires when the value of the element changes.
2.0+1.0+1.0+4.0+1.0+
 
Fires when the element is clicked.
2.0+1.0+1.0+4.0+1.0+
 
Fires when the user closes the window.
2.0+1.0+1.0+4.0+1.0+
 
Fires when a user drops a file onto the window.
nono4.0+nono
 
Event handler for errors raised on a window.
3.0+1.0+2.0+7.0+1.0+
 
Event handler for focus events on a window.
3.0+1.0+2.0+7.0+1.0+
 
Fires when a user presses the F1 key to activate help.
4.0+nononono
 
Fires when a user presses down on a key while the element has focus.
2.0+1.0+1.0+4.0+1.0+
 
Fires when a user presses a key or holds down the key while the element has focus.
2.0+1.0+1.0+4.0+1.0+
 
Fires when a user releases a key while the element has focus.
2.0+1.0+1.0+4.0+1.0+
 
Event handler for window loading.
3.0+1.0+2.0+7.0+1.0+
 
Fires when a user clicks down on the mouse button while the element has focus.
2.0+1.0+1.0+4.0+1.0+
 
Fires when the mouse moves while the pointer over the element.
2.0+1.0+1.0+4.0+1.0+
 
Fires when the mouse pointer moves off of the element.
2.0+1.0+1.0+4.0+1.0+
 
Fires when the mouse pointer moves over the element.
2.0+1.0+1.0+4.0+1.0+
 
Fires when the user releases the mouse button while the element has focus.
2.0+1.0+1.0+4.0+1.0+
 
Event handler for window move events.
no1.0+4.0+7.0+1.0+
 
Fires when the form data is reset.
2.0+1.0+1.0+4.0+1.0+
 
Event handler for window resizing.
3.0+1.0+2.0+7.0+1.0+
 
Fires when a user scrolls the element.
4.0+nonono1.0+
 
Fires when the element is selected.
2.0+1.0+1.0+4.0+1.0+
 
Fires when the form data is submitted.
2.0+1.0+1.0+4.0+1.0+
 
Event handler for unload events on the window.
3.0+1.0+2.0+7.0+1.0+
 
Gets or sets the text in the status bar at the bottom of a web browser window.
3.0+1.0+2.0+7.0+1.0+
 
Indicates whether a window is closed or not.
4.0+1.0+3.0+7.0+1.0+
 
Reference to the document that the window contains.
3.0+1.0+2.0+7.0+1.0+
 
Instance of an Event that is available to an event handler.
4.0+nono7.0+1.0+
 
An array of the frames in the current window.
3.0+1.0+2.0+7.0+1.0+
 
Reference to the History object.
3.0+1.0+3.0+7.0+1.0+
 
Number of frames in the window.
3.0+1.0+2.0+7.0+1.0+
 
Gets or sets the current URL of a window.
3.0+1.0+2.0+7.0+1.0+
 
Reference to an object holding math functions and constants.
3.0+1.0+2.0+nono
 
Reference to the Navigator object.
3.0+1.0+6.0+7.0+1.0+
 
Reference to the window that opened the current window.
3.0+1.0+3.0+7.0+1.0+
 
Reference to the parent of the current window or subframe.
3.0+1.0+2.0+7.0+1.0+
 
Reference to the Screen object associated with the window.
4.0+1.0+6.0+7.0+1.0+
 
Reference to a Window object itself.
3.0+1.0+2.0+7.0+1.0+
 
Reference to the top window in the window hierarchy.
3.0+1.0+2.0+7.0+1.0+
 
Reference to the current Window.
3.0+1.0+2.0+7.0+1.0+
 
Reference to an XMLHttpRequest object.
5.0+1.0+7.0+no1.2+
 

Methods

MethodIEMozillaNetscapeOperaSafari
Displays an alert dialogue box.
3.0+1.0+2.0+7.0+1.0+
 
Moves back one step in the Window history.
1.0+4.0+7.0+1.0+
 
Removes focus from the Window.
4.0+1.0+3.0+7.0+1.0+
 
Sets the Window to capture all events of the specified type.
nono4.0+nono
 
Clears a delay that was set with the setInterval method.
4.0+1.0+4.0+7.0+1.0+
 
Clears a timeout that was set with the setTimeout method.
3.0+1.0+2.0+7.0+1.0+
 
Closes the current window.
3.0+1.0+2.0+7.0+1.0+
 
Displays a confirmation dialogue box.
3.0+1.0+2.0+7.0+1.0+
 
Sets the focus on the current Window.
4.0+1.0+3.0+7.0+1.0+
 
Moves forward one step in the Window history.
nono4.0+7.0+no
 
Computes style information and returns the CSSStyleDeclaration for the specified document Element.
6.0+1.0+6.0+no1.0+
 
Calls the event handler for the specified event.
nono4.0+nono
 
Returns the browser Window to the browser home page.
nono4.0+7.0+no
 
Moves a Window by the specified amount.
4.0+1.0+4.0+7.0+1.0+
 
Moves the Window to the specified location.
4.0+1.0+4.0+7.0+1.0+
 
Automatically navigates to the specified URL.
3.0+nononono
 
Opens a new Window.
3.0+1.0+2.0+7.0+1.0+
 
Prints the contents of the current Window.
5.0+1.0+4.0+7.0+no
 
Displays a dialogue box that prompts the user for input.
3.0+1.0+2.0+7.0+1.0+
 
Sets the Window to release all captured events of a specified type.
nono4.0+7.0+no
 
Resizes the current window by the specified amount.
4.0+no4.0+7.0+1.0+
 
Resizes the current window to the specified size.
4.0+no4.0+7.0+1.0+
 
Routes a captured event through the event hierarchy.
nono4.0+nono
 
Scrolls the window to a specified place in the document.
4.0+1.0+3.0+no1.0+
 
Scrolls the current document in the window by the specified amount.
4.0+1.0+4.0+7.0+1.0+
 
Scrolls the window to a specified place in the document.
4.0+1.0+4.0+7.0+1.0+
 
Calls a function or evaluates an expression every time the specified interval elapses.
4.0+1.0+4.0+7.0+1.0+
 
Specifies a delay for calling a function or evaluating an expression.
3.0+1.0+2.0+7.0+1.0+
 
Stops the window from loading.
nono4.0+7.0+no
 

References

Document | AbstractView

Availability

JavaScript 1.0 | enhanced in JavaScript 1.1 and 1.2

Constructor Detail

Window Window()

Creates a new instance of a Window object.

Visibility
internal

Property Detail

String defaultStatus

Gets or sets the default text in the status bar at the bottom of a web browser window.

See Also

Window.status

Availability

JavaScript 1.0

String name

Gets or sets the name of a window.

See Also

Form.target | Link.target

Availability

JavaScript 1.0 | read/write in JavaScript 1.1

static Function onabort - read only

Fires when the loading of the element is cancelled before it finishes loading.

static Function onafterprint - read only

Fires immediately after a user prints or print previews a document.

static Function onbeforeprint - read only

Fires immediately before a user prints or print previews a document.

static Function onbeforeunload - read only

Fires immediately before a document is unloaded.

static Function onblur - read only

Event handler for blur events on a window.

See Also

Window.blur | Window.focus | Window.onfocus | Event | EventListener | EventTarget

Availability

HTML DOM Level 0

static Function onchange - read only

Fires when the value of the element changes.

static Function onclick - read only

Fires when the element is clicked.

static Function onclose - read only

Fires when the user closes the window.

static Function ondragdrop - read only

Fires when a user drops a file onto the window.

static Function onerror - read only

Event handler for errors raised on a window.

Availability

JavaScript 1.1 | buggy in Netscape 6/6.1

static Function onfocus - read only

Event handler for focus events on a window.

See Also

Window.blur | Window.focus | Window.onblur | Event | EventListener | EventTarget

Availability

JavaScript 1.1

static Function onhelp - read only

Fires when a user presses the F1 key to activate help.

static Function onkeydown - read only

Fires when a user presses down on a key while the element has focus.

static Function onkeypress - read only

Fires when a user presses a key or holds down the key while the element has focus.

static Function onkeyup - read only

Fires when a user releases a key while the element has focus.

static Function onload - read only

Event handler for window loading.

See Also

Window.onunload | Event | EventListener | EventTarget

Availability

JavaScript 1.0

static Function onmousedown - read only

Fires when a user clicks down on the mouse button while the element has focus.

static Function onmousemove - read only

Fires when the mouse moves while the pointer over the element.

static Function onmouseout - read only

Fires when the mouse pointer moves off of the element.

static Function onmouseover - read only

Fires when the mouse pointer moves over the element.

static Function onmouseup - read only

Fires when the user releases the mouse button while the element has focus.

static Function onmove - read only

Event handler for window move events.

static Function onreset - read only

Fires when the form data is reset.

static Function onresize - read only

Event handler for window resizing.

Availability

JavaScript 1.2

static Function onscroll - read only

Fires when a user scrolls the element.

static Function onselect - read only

Fires when the element is selected.

static Function onsubmit - read only

Fires when the form data is submitted.

static Function onunload

Event handler for unload events on the window.

See Also

Window.onload | Event | EventListener | EventTarget

Availability

JavaScript 1.0

String status

Gets or sets the text in the status bar at the bottom of a web browser window.

See Also

Window.defaultStatus

Availability

JavaScript 1.0

Boolean closed

Indicates whether a window is closed or not.

Document document

Reference to the document that the window contains.

See Also

Document

Event event

Instance of an Event that is available to an event handler.

See Also

Event

Array frames

An array of the frames in the current window.

History history

Reference to the History object.

See Also

History

Number length

Number of frames in the window.

Location location

Gets or sets the current URL of a window.

Math Math

Reference to an object holding math functions and constants.

See Also

Math

Navigator navigator

Reference to the Navigator object.

See Also

Navigator

Window opener

Reference to the window that opened the current window.

Window parent

Reference to the parent of the current window or subframe.

Screen screen

Reference to the Screen object associated with the window.

See Also

Screen

Window self

Reference to a Window object itself.

Window top

Reference to the top window in the window hierarchy.

Window window

Reference to the current Window.

See Also

Window

XMLHttpRequest XMLHttpRequest

Reference to an XMLHttpRequest object.

See Also

XMLHttpRequest

Availability

HTML DOM Level 3

Method Detail

alert() : void

Displays an alert dialogue box.

See Also

Window.confirm | Window.prompt

Availability

JavaScript 1.0

back() : void

Moves back one step in the Window history.

blur() : void

Removes focus from the Window.

See Also

Window.focus

Availability

JavaScript 1.1

captureEvents(Number eventmask) : void

Sets the Window to capture all events of the specified type.

NumbereventmaskType of event to capture.

See Also

Event | Window.handleEvent | Window.releaseEvents | Window.routeEvent | EventTarget.addEventListener

clearInterval(Object intervalId) : void

Clears a delay that was set with the setInterval method.

ObjectintervalIdIdentifier for the interval.

See Also

Window.setInterval

Availability

HTML DOM Level 0

clearTimeout(Object timeoutId) : void

Clears a timeout that was set with the setTimeout method.

ObjecttimeoutIdIdentifier for the timeout.

See Also

Window.setTimeout

Availability

HTML DOM Level 0

close() : void

Closes the current window.

See Also

Window.open | the closed and opener properties of Window

Availability

JavaScript 1.0

confirm(String question) : Boolean

Displays a confirmation dialogue box.

StringquestionText to display to ask the user a "yes" or "no" question to confirm or cancel.

See Also

Window.alert | Window.prompt

Availability

HTML DOM Level 0

focus() : void

Sets the focus on the current Window.

See Also

Window.blur

Availability

HTML DOM Level 0

forward() : void

Moves forward one step in the Window history.

getComputedStyle(Element elt, String pseudoElt) : static CSSStyleDeclaration

Computes style information and returns the CSSStyleDeclaration for the specified document Element.

ElementeltDocument element to get the style information for.
StringpseudoEltCSS pseudoelement.

See Also

CSS2Properties | CSSStyleDeclaration | HTMLElement.style

Availability

HTML DOM Level 2

handleEvent(Object event) : Object

Calls the event handler for the specified event.

ObjecteventEvent to have the event handler called for.

See Also

Window.routeEvent

home() : void

Returns the browser Window to the browser home page.

Availability

HTML DOM Level 0

moveBy(Number dx, Number dy) : void

Moves a Window by the specified amount.

NumberdxNumber of pixels to move the window to the right. Use a negative value to move the window to the left.
NumberdyNumber of pixels to move the window towards the bottom of the screen. Use a negative value to move the window up.

Availability

JavaScript 1.2

moveTo(Object x, Object y) : void

Moves the Window to the specified location.

ObjectxNumber of pixels from the left edge of the screen to set the horizontal position.
ObjectyNumber of pixels from the top edge of the screen to set the vertical position.

Availability

JavaScript 1.2

navigate(String url) : void

Automatically navigates to the specified URL.

StringurlURL to navigate to.

See Also

Location | Window.location

open([String url,] [String name,] [String features,] [Boolean replace]) : Window

Opens a new Window.

StringurlSets the URL of the new Window. (optional)
StringnameSets the name of the new Window. (optional)
StringfeaturesComma-separated list of features for the new Window to have. (optional)
BooleanreplaceWhether or not the URL in the new window should create a new entry in the browser history or replace the current URL. (optional)

See Also

Location.replace | Window.close | the closed and opener properties of Window

Availability

HTML DOM Level 0

print() : void

Prints the contents of the current Window.

Availability

HTML DOM Level 0

prompt(String message, String default) : StringNumber

Displays a dialogue box that prompts the user for input.

StringmessageText message or question to display to the user.
StringdefaultDefault value to display in the text field.

See Also

Window.alert | Window.confirm

Availability

HTML DOM Level 0

releaseEvents(Number eventmask) : void

Sets the Window to release all captured events of a specified type.

NumbereventmaskType of event to stop capturing.

See Also

Event | Window.captureEvents | Window.handleEvent | Window.routeEvent | EventTarget.removeEventListener

resizeBy(Number dw, Number dh) : void

Resizes the current window by the specified amount.

NumberdwNumber of pixels to resize the window horizontally.
NumberdhNumber of pixels to resize the window vertically.

Availability

JavaScript 1.2

resizeTo(Object width, Object height) : void

Resizes the current window to the specified size.

ObjectwidthNumber of pixels wide that the window should be.
ObjectheightNumber of pixels tall that the window should be.

routeEvent(Function event) : Object

Routes a captured event through the event hierarchy.

FunctioneventEvent to be routed.

See Also

Window.captureEvents | Window.handleEvent | Window.releaseEvents

scroll(Object x, Object y) : void

Scrolls the window to a specified place in the document.

ObjectxHorizontal position (in pixels) to scroll to.
ObjectyVertical position (in pixels) to scroll to.

Availability

JavaScript 1.1 | deprecated in JavaScript 1.2

scrollBy(Number dx, Number dy) : void

Scrolls the current document in the window by the specified amount.

NumberdxNumber of pixels to scroll horizontally.
NumberdyNumber of pixels to scroll vertically.

Availability

JavaScript 1.2

scrollTo(Object x, Object y) : void

Scrolls the window to a specified place in the document.

ObjectxHorizontal position (in pixels) to scroll to.
ObjectyVertical position (in pixels) to scroll to.

Availability

JavaScript 1.2

setInterval(String code, Function func, Number interval, Array args...) : Number

Calls a function or evaluates an expression every time the specified interval elapses.

StringcodeExpression to be evaluated (not required if func is used).
FunctionfuncFunction to be called (not required if code is used).
NumberintervalNumber of milliseconds to wait.
Arrayargs...Arguments (if any) to be taken by the function. (zero-or-more)

See Also

Window.clearInterval | Window.setTimeout

Availability

JavaScript 1.2 | IE 4 supports only one of the two forms

setTimeout(String code, Function func, String delay, Array args) : Number

Specifies a delay for calling a function or evaluating an expression.

StringcodeExpression to be evaluated (not required if func is used).
FunctionfuncFunction to be called (not required if code is used).
StringdelayNumber of milliseconds to wait.
ArrayargsArguments (if any) to be taken by the function.

See Also

Window.clearTimeout | Window.setInterval

Availability

JavaScript 1.0

stop() : void

Stops the window from loading.

Availability

HTML DOM Level 0