Window Object
The Window object corresponds to the browser window. A Window object is created automatically with every instance
of a <body> or <frameset> tag.
The Window object's collections, objects, properties, methods, and events are described below:
N: Netscape (including Mozilla when N6 or higher), IE: Internet Explorer
Collections
Collection |
Description |
N |
IE |
frames[] |
Returns all named frames in the window |
2 |
3.02 |
Objects
Object |
Description |
N |
IE |
clientInformation |
Contains information about the browser |
|
4 |
clipboardData |
|
|
5 |
document |
Represents the HTML document object in the window.
See Document object |
|
3.02 |
event |
Represents the state of an event |
|
4 |
external |
|
|
4 |
history |
Contains the URLs visited from the window.
See History object |
|
3.02 |
location |
Contains the current URL of the window.
See Location object |
|
3.02 |
navigator |
Contains information about the browser.
See Navigator object |
|
3.02 |
screen |
Contains information about the client's screen.
See Screen object |
|
4 |
Properties
Syntax: window.property_name
Property |
Description |
N |
IE |
closed |
Returns a Boolean value that specifies whether the
referenced window has been closed |
3 |
4 |
defaultStatus |
Sets or returns the default text in the statusbar of the
windows (will be
displayed when the page loads) |
2 |
3.02 |
dialogArguments |
Returns all variables passed into the modal dialog window |
|
4 |
dialogHeight |
Sets or returns the height of the modal dialog window |
|
4 |
dialogLeft |
Sets or returns the left coordinates of the modal dialog
window |
|
4 |
dialogTop |
Sets or returns the top coordinates of the modal dialog
window |
|
4 |
dialogWidth |
Sets or returns the width of the modal dialog window |
|
4 |
frameElement |
Returns the frame/iframe object that is hosting the window
in the parent document |
|
5.5 |
length |
Sets or returns the number of frames in the window |
6 |
4 |
name |
Sets or returns the name of the window |
2 |
3.02 |
offscreenBuffering |
Sets or returns a Boolean value that specifies whether the
window is drawn offscreen before being visible to the user |
|
4 |
opener |
Sets or returns a reference to the window that created the
window |
3 |
4 |
parent |
Returns the parent window |
2 |
3.02 |
returnValue |
Sets or returns the value returned from the modal dialog
window |
|
4 |
screenLeft |
Returns the x-coordinate of the upper left corner of the
browser - relative to the upper left corner of the screen |
|
5 |
screenTop |
Returns the y-coordinate of the top corner of the browser -
relative to the top corner of the screen |
|
5 |
self |
Returns a reference to the current window |
2 |
3.02 |
status |
Sets or returns the text in the statusbar of the window |
2 |
3.02 |
top |
Returns the topmost ancestor window |
2 |
3.02 |
Methods
Syntax: window.method_name()
Method |
Description |
N |
IE |
alert("msg") |
Displays an alert box with a message and an OK button |
2 |
3.02 |
attachEvent("event",pointer) |
|
|
5 |
blur() |
Removes focus from the current window |
3 |
4 |
clearInterval(ID) |
Cancels a timeout that is set with the setInterval() method |
4 |
4 |
clearTimeout(ID) |
Cancels a timeout that is set with the setTimeout() method |
2 |
3.02 |
close() |
Closes the current window |
2 |
3.02 |
confirm("msg") |
Displays a dialog box with a message, a Cancel, and an OK
button |
2 |
3.02 |
createPopup([args]) |
Creates a pop-up window |
|
5.5 |
execScript("code", "lang") |
Executes a specified script. The arguments can take the following values:
code |
Required. The code to be executed |
lang |
Required. JScript | VBScript | JavaScript |
|
|
4 |
focus() |
Sets focus on the current window |
3 |
4 |
moveBy(x,y) |
Moves the window a specified number of pixels in relation
to its current co-ordinates |
4 |
4 |
moveTo(x,y) |
Moves the window's left and top edge to the specified co-ordinates |
4 |
4 |
navigate("URL") |
Loads the specified URL into the window |
|
3.02 |
open(["URL", "name", "specs", replace]) |
Opens a new browser window. The arguments can take the
following values:
"URL" - Optional. Specifies the URL of the page to display
if no URL is specified, a new window with about:blank is displayed)
"name" - Optional. Specifies the value for the target attribute on a form or a link.
The following values are supported:
_blank |
URL is loaded into a new window |
_media |
URL is loaded into the content area of the Media Bar (IE6+) |
_parent |
URL is loaded into the parent frame |
_search |
URL is opened in the browser's search pane (IE5+) |
_self |
URL replaces the current page |
_top |
URL replaces any framesets that may be loaded |
"specs" - Optional. A comma-separated list of items. The following
values are supported:
channelmode = yes | no | 1 | 0 |
whether to display the window in theater mode. Default is no |
directories = yes | no | 1 | 0 |
whether to add directory buttons. Default is yes |
fullscreen = yes | no | 1 | 0 |
whether to display the browser in full-screen mode. Default is no. A window in full-screen mode must also be in theater mode |
height = number |
the height of the window, in pixels. Min. value is 100 |
left = number |
the left position, in pixels |
location = yes | no | 1 | 0 |
whether to display the address field. Default is yes |
menubar = yes | no | 1 | 0 |
whether to display the menu bar. Default is yes |
resizable = yes | no | 1 | 0 |
whether the window is resizable. Default is yes |
scrollbars = yes | no | 1 | 0 |
whether to display scroll bars. Default is yes |
status = yes | no | 1 | 0 |
whether to add a status bar. Default is yes |
titlebar = yes | no | 1 | 0 |
whether to display the title bar. Ignored unless the calling application is an HTML Application or a trusted dialog box. Default is yes |
toolbar = yes | no | 1 | 0 |
whether to display the browser toolbar. Default is yes |
top = number |
the top position, in pixels |
width = number |
the width of the window, in pixels. Min. value is 100 |
width = number |
the width of the window, in pixels. Min. value is 100 |
replace - Optional.Specifies whether the URL creates a new entry or replaces the current entry in the history list.
The following values are supported:
true |
URL replaces the current document in the history list |
false |
URL creates a new entry in the history list |
|
|
3.02 |
print() |
Prints the contents of the current window |
4 |
5 |
prompt(["msg", "default"]) |
Displays a dialog box prompting the user for input. The arguments can take the following values:
msg |
Optional. The message to display in the dialog box. Default
is "" |
default |
Optional. The default text in the input field |
|
2 |
3.02 |
resizeBy(x,y) |
Resizes the window by the specified pixels. Note:
This method does not work on dialog windows |
|
4 |
resizeTo(width, height) |
Resizes the window to the specified width and height.
Note: This method does not work on dialog windows |
|
4 |
scroll(x,y) |
Deprecated. Use scrollTo() instead. |
|
4 |
scrollBy(x,y) |
Scrolls the content by the specified number
of pixels. Note: The visible property of the window's scrollbar must
be set to true if using this method |
4 |
4 |
scrollTo(x,y) |
Scrolls the content to the specified co-ordinates |
4 |
4 |
setActive() |
|
|
5.5 |
setInterval(code, millisec[, "lang"]) |
Calls a function / evaluate an expression every time a specified
interval (in milliseconds) has been reached. The arguments can take the following values:
code |
Required. A pointer to a function or the code to be executed |
millisec |
Required. The number of milliseconds |
lang |
Optional. JScript | VBScript | JavaScript |
|
4 |
4 |
setTimeout(code, millisec[, "lang"]) |
Calls a function / evaluate an expression after a specified
number of milliseconds. The arguments can take the following values:
code |
Required. A pointer to a function or the code to be executed |
millisec |
Required. The number of milliseconds |
lang |
Optional. JScript | VBScript | JavaScript |
|
|
3.02 |
showHelp("URL"[, contextID]) |
Displays a Help file (must be of type .htm or .chm). When
using this method, a second Help box appears when pressing F1 or when
clicking Help on the menu bar. To prevent the default Help box from
appearing set returnValue to false. The arguments can take the following values:
URL |
Required. The URL of a Help file |
contextID |
Optional. A string or integer that specifies a context
identifier in the Help file |
|
|
4 |
showModalDialog("URL"[, args, "list"]) |
Loads a URL in a modal dialog box. A modal dialog box
retains focus while open. The user CANNOT switch windows until the dialog
box is closed. The arguments can take the following values:
"URL" - Required. The URL of the document to display.
args - Optional. The arguments to use when displaying the URL. Use this parameter to pass a value of any type, including an
array of values. The dialog box can extract the values from the dialogArguments property of the window object.
"list" - Optional. Specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values:
dialogHeight : number |
the height* of the dialog window |
dialogLeft : number |
the left position of the dialog window |
dialogTop : number |
the top position of the dialog window |
dialogWidth : number |
the width* of the dialog window |
center : yes | no | 1 | 0 | on | off |
whether to center the dialog window within the desktop. Default is yes |
dialogHide : yes | no | 1 | 0 | on | off |
whether the dialog window is hidden when printing. Only available when a dialog box is opened from a trusted application. Default is no |
edge : sunken | raised |
the edge style of the dialog window. Default is raised |
help : yes | no | 1 | 0 | on | off |
whether the dialog window displays the Help icon. Default is yes |
resizable : yes | no | 1 | 0 | on | off |
whether the dialog window is resizable. Default is no |
scroll : yes | no | 1 | 0 | on | off |
whether the dialog window displays scrollbars. Default is yes |
status : yes | no | 1 | 0 | on | off |
whether the dialog window displays a status bar. Default is yes for untrusted dialog windows and no for trusted dialog windows |
unadorned : yes | no | 1 | 0 | on | off |
whether the dialog window displays the border window chrome. Only available when a dialog window is opened from a trusted application. Default is no |
|
|
4 |
showModelessDialog("URL"[, args, "list"]) |
Loads a URL in a modeless dialog box. The modeless dialog
box displays even when the user switches focus to another window (useful for
menus and Help systems). The arguments can take the following values:
"URL" - Required. The URL of the document to display.
args - Optional. The arguments to use when displaying the URL. Use this parameter to pass a value of any type, including an
array of values. The dialog box can extract the values from the dialogArguments property of the window object.
"list" - Optional. Specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values:
dialogHeight : number |
the height* of the dialog window |
dialogLeft : number |
the left position of the dialog window |
dialogTop : number |
the top position of the dialog window |
dialogWidth : number |
the width* of the dialog window |
center : yes | no | 1 | 0 | on | off |
whether to center the dialog window within the desktop. Default is yes |
dialogHide : yes | no | 1 | 0 | on | off |
whether the dialog window is hidden when printing. Only available when a dialog box is opened from a trusted application. Default is no |
edge : sunken | raised |
the edge style of the dialog window. Default is raised |
help : yes | no | 1 | 0 | on | off |
whether the dialog window displays the Help icon. Default is yes |
resizable : yes | no | 1 | 0 | on | off |
whether the dialog window is resizable. Default is no |
scroll : yes | no | 1 | 0 | on | off |
whether the dialog window displays scrollbars. Default is yes |
status : yes | no | 1 | 0 | on | off |
whether the dialog window displays a status bar. Default is yes for untrusted dialog windows and no for trusted dialog windows |
unadorned : yes | no | 1 | 0 | on | off |
whether the dialog window displays the border window chrome. Only available when a dialog window is opened from a trusted application. Default is no |
|
|
5 |
* The default unit of measure for dialogHeight and dialogWidth in IE4 is
em; in IE5 it is px. Other values to use: cm, mm, in, pt, pc, or ex. For consistent results, use px! Note:
The min. dialogHeight you can specify is 100px.
Events
Syntax: window.event_name="someJavaScriptCode"
Event |
Description |
N |
IE |
onBlur |
Executes some code when a Blur event occurs |
3 |
|
onError |
Executes some code when an Error event occurs |
3 |
|
onFocus |
Executes some code when a Focus event occurs |
3 |
|
onLoad |
Executes some code when an Load event occurs |
2 |
|
onResize |
Executes some code when a Resize event occurs |
4 |
|
onUnload |
Executes some code when an Unload event occurs |
2 |
|
|