Site hosted by Angelfire.com: Build your free website today!
Home:JavaScript:window

The window object

Top level of the Document Object Model

On this page:

Properties

Methods

Event handlers

Top

The window object represents a browser window. You can create a new window in the browser by naming a new window object in JavaScript. Every document is contained in a window, so the window object stands at the top level of the Document Object Model.

Here are the properties and methods of the window object.

Properties
PropertyData typeRemarksJS version
location string The URL of the document loaded in this window. 1.0
history integer Refers to other pages loaded during the current browser session. ??
name string The name of the window. This is a name assigned by the script. It is not the document title or filename. Frames may also have their names assigned by an HTML tag: <FRAME NAME="name"> 1.0
status string Text to display in the browser’s status bar. The text will scroll across the status bar repeatedly. (Do not overuse this property.) 1.0
defaultStatus string Default message to be displayed. 1.0
frames[] array Frames contained in this window. (Each frame is also a separate window object.) 1.0
self object The current window. 1.0
parent object Frames only: The frameset window that contains the current frame window. 1.0
top object The top window of a frameset. 1.0
closed boolean Is the window closed? (true, false) 1.1
Methods
MethodRemarksJS version
open() Opens a new window. 1.0
close() Closes the current window. You may only close window objects that were opened with the open() method (not the user’s main browser window). 1.0
alert() Displays a dialog box with your text message and an "OK" button. Interrupts rendering of the page until "OK" is pressed. 1.0
confirm() Displays a dialog box with your text message and two buttons: "OK" and "Cancel". Returns a boolean value for the clicked button: true for "OK", false for "Cancel". 1.0
prompt() Displays a dialog box with your message, a text entry box, and "OK" and "Cancel" buttons. Returns the user's typed-in string when "OK" is clicked, or the boolean value false when "Cancel" is clicked. 1.0
scrollBy() Scrolls the window by the specified distance (in pixels). 1.2
scrollTo() Scrolls the window to a point you specify (x,y coordinates of the point that will be moved to the upper-left corner of the browser window). 1.2
moveBy() Moves the window the distance you specify (in pixels). 1.2
moveTo() Moves the upper-left corner of the window to the screen coordinates you specify. 1.2
resizeBy() Resizes the window by the amount you specify. 1.2
resizeTo() Resizes the window to the dimensions you specify. 1.2
setTimeout() Defers the execution of JavaScript code by a specified amount of time. 1.0
clearTimeout() Stops execution of deferred code set with setTimeout(). VerVer
setInterval() Periodically executes specified JavaScript code. 1.2
clearInterval() Stops executing code that you started with setInterval(). 1.2
Event handlers
Event handlerWhen it’s activatedJS version
onLoad() When the document in the window is loaded (completely). 1.0
onFocus() When the window is selected or made active by the user. 1.1
onBlur() When the window is no longer active (e.g., when another window is selected). 1.1
onResize() When the window is resized. (This handler may inadvertently cause onLoad to be activated after the window is resized.) 1.2
onError() When a JavaScript error occurs. 1.1
onUnload() When the document in the current window is “unloaded” (replaced by another page). This handler is not really a good idea. 1.0