You are here: Reference > JavaScript > client-side > HTML DOM > objects > window

window object

Browser support:
Represents the browser window, frame window or dialog window of a HTML document.
The window object provides various information about the window (name, navigator, location, history, etc.), provides access to the document contained by the window and supports several useful methods (alert, confirm, addEventListener, attachEvent, etc.).
The window object can also represent a window that belongs to a frame or iframe element or a modal or modeless dialog (open, showModalDialog and showModelessDialog methods).
  • If a window belongs to a frame or iframe element, then it is the child window of the window that contains the frame element. To get the parent window, use the parent property of the child window.
  • If a window is opened with the open, showModalDialog or showModelessDialog method, then the window that opened it can be retrieved with the opener property.
The members of the current window are accessible directly, without using the window object as a prefix (e.g. you can use document instead of window.document), furthermore the global variables and objects are also accessible through the window object (var x = 2; alert (window.x);).
The window object is accessible from anywhere in the JavaScript code, so do not use variables with the same names as the members of the window object (although if you declare a variable with the same name as any member of the window object, the member of the window object stays accessible through the window object).

Syntax:

Properties that reference the object:
window
+object.contentWindow
Related HTML objects:
external.menuArguments
document.parentWindow
event.source
event.view
Methods that return the object:
frames.item (nameOrIndex)
The base interface, through which you can add new functionalities to the window object, is the Window interface.

Possible members:

Properties
Methods
Events
_content
Returns a reference to the topmost ancestor window object in the window hierarchy.
clientInformation
Contains information about the browser and the operating system of the user.
clipboardData
Allows access to the data placed on the system clipboard.
closed
Returns a Boolean value that indicates whether the window is closed or not.
Components
Implements the XPConnect (Cross Platform Connect) technology that provides interaction between XPCOM (Cross Platform Component Object Model) and JavaScript.
content
Returns a reference to the topmost ancestor window object in the window hierarchy.
crypto
Represents the security object of the Firefox browser. The crypto object allows access to various browser security and cryptographic features.
defaultStatus
Sets or returns the default message in the status bar.
dialogArguments
3
Returns a variable that was passed as an extra argument to a modal dialog window created with the window.showModalDialog or window.showModelessDialog method.
dialogHeight
Specifies or retrieves the height of the dialog window.
dialogLeft
Specifies or retrieves the left position of the dialog window.
dialogTop
Specifies or retrieves the top position of the dialog window.
dialogWidth
Specifies or retrieves the width of the dialog window.
directories
Represents a bar object in Firefox, Google Chrome and Safari.
document
Represents an entire HTML document and provides possibilities for accessing, creating and manipulating all elements in the document.
event
Represents an object that contains information about an event that has occurred.
external
Returns a reference to the external object in Internet Explorer and the sidebar object in Firefox.
frameElement
Returns a reference to the frame or iframe element that hosts the current window in the parent document.
frames
Represents a collection of all window objects that belong to frame and iframe elements in the current document.
fullScreen
3
Specifies or retrieves whether the browser application is in full-screen mode or not.
history
Provides access to the browser history that contains the URLs of visited pages.
innerHeight
9
Returns the height of the browser's client area, including the horizontal scrollbar, if rendered.
innerWidth
9
Returns the width of the browser's client area, including the vertical scrollbar, if rendered.
length
Returns the number of frames (frame or iframe) in the current window.
location
Contains information about the URL of the currently loaded document, and provides methods to navigate to a new page.
locationbar
Represents a bar object in Firefox, Google Chrome and Safari.
menubar
Represents a bar object in Firefox, Google Chrome and Safari.
name
Sets or retrieves the name of the current window object, which is used to identify the window.
navigator
Contains information about the browser and the operating system of the user.
offscreenBuffering
Specifies or returns whether the off-screen buffer needs to be used for drawing.
opener
Sets or retrieves a reference to the window that opened the current document.
opera
Supports some Opera specific methods.
outerHeight
9
Sets or retrieves the total height of the browser window, including toolbars and scrollbars.
outerWidth
9
Sets or retrieves the total width of the browser window, including toolbars and scrollbars.
pageXOffset
9
Retrieves the number of pixels by which the contents of the document are scrolled to left.
pageYOffset
9
Retrieves the number of pixels by which the contents of the document are scrolled upward.
parent
Returns a reference to the immediate parent window object in the window hierarchy.
personalbar
Represents a bar object in Firefox, Google Chrome and Safari.
pkcs11
Retrieves a reference to the pkcs11 object. Use this object to install drivers or other software.
returnValue
3
Specifies or retrieves the value returned from a modal dialog window.
screen
Contains information about the dimensions of the screen and the display settings.
screenLeft
Returns an integer value that indicates the horizontal position of the left side of the browser's client area, relative to the left side of the screen.
screenTop
Returns an integer value that indicates the vertical position of the top side of the browser's client area, relative to the top side of the screen.
screenX
9
Returns an integer value that indicates the horizontal position of the left side of the browser window, relative to the left side of the screen.
screenY
9
Returns an integer value that indicates the vertical position of the top side of the browser window, relative to the top side of the screen.
scrollbars
Represents a bar object in Firefox, Google Chrome and Safari.
scrollMaxX
Returns the maximum number of pixels by which the contents of the document can be scrolled horizontally.
scrollMaxY
Returns the maximum number of pixels by which the contents of the document can be scrolled vertically.
scrollX
Retrieves the number of pixels by which the contents of the document are scrolled to the left.
scrollY
Retrieves the number of pixels by which the contents of the document are scrolled upward.
self
Returns a reference to the window object itself.
sidebar
Provides methods for registering add-ons with the Firefox browser.
status
Sets the message in the status bar or retrieves the previously specified value.
statusbar
Represents a bar object in Firefox, Google Chrome and Safari.
toolbar
Represents a bar object in Firefox, Google Chrome and Safari.
top
Returns a reference to the topmost ancestor window object in the window hierarchy.

Example HTML code 1:

This example shows how to open a child window and communicate between the opener and the child windows:
Code
childWindow.htm
<head>
    <script type="text/javascript">
        function OpenChildWindow () {
            window.open ("childWindow.htm", "OpenerTest", "width=300, height=200");
        }
    </script>
</head>
<body>
    First open a child window with this button:
    <button id="childOpener" onclick="OpenChildWindow ();">Open child window!</button>
    <br /><br />
    You can change the text color of the button with the selection list of the child window.
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content