Window object (Object/browser)

An object representing a window or frame. This object exposes methods, properties, and events associated with it to the script.

Availability:

JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
JavaScript syntax:-myWindow = aFrameName
-myWindow = frames[anIndex]
-myWindow = opener
-myWindow = parent
-myWindow = self
-myWindow = top
-myWindow = window
-myWindow = window.open()
IEmyWindow = document.parentWindow
IEmyWindow = frame
Argument list:anIndexAn index to a window object
aFrameNameThe name of a frame in the window
Object properties:clientInformation, clipboardData, closed, crypto, defaultStatus, dialogArguments, dialogHeight, dialogLeft, dialogTop, dialogWidth, document, event, external, frame, frameRate, history, innerHeight, innerWidth, java, length, location, locationbar, Math, menubar, name, navigator, netscape, offScreenBuffering, opener, outerHeight, outerWidth, Packages, pageXOffset, pageYOffset, parent, personalbar, pkcs11, returnValue, screen, screenLeft, screenTop, screenX, screenY, scrollbars, secure, self, sidebar, status, statusbar, sun, toolbar, top, window
Object methods:alert(), attachEvent(), back(), blur(), clearInterval(), clearTimeout(), close(), confirm(), detachEvent(), disableExternalCapture(), enableExternalCapture(), execScript(), find(), focus(), forward(), home(), moveBy(), moveTo(), navigate(), open(), print(), prompt(), resizeBy(), resizeTo(), scroll(), scrollBy(), scrollTo(), setHotkeys(), setInterval(), setResizable(), setTimeout(), setZOptions(), showHelp(), showModalDialog(), showModelessDialog(), stop()
Functions:atob(), btoa(), captureEvents(), handleEvent(), releaseEvents(), routeEvent()
Event handlers:onAfterPrint, onBeforePrint, onBeforeUnload, onBlur, onDragDrop, onError, onFocus, onHelp, onLoad, onMouseMove, onMove, onResize, onScroll, onUnload
Collections:frames[]

The window object was introduced when JavaScript was made available at version 1.0. It has been revised several times and is likely to gain new functionality with every release.

This object is added to the scope chain as the global object when scripts are executed in a web browser. This means that the properties and methods are available without needing the window prefix.

In a web browser this IS the global object. Adding properties (variables) during script execution adds them to the window object for the window in which the page containing the script is loaded.

The window represents the browser container that the document object lives in.

Since the on-screen window persists as long as the window is open, you might think it may be a useful place to store some session state data between documents. Clearly, storing session data in a document object is no use if the document is going to be discarded and replaced. However, anything created by a script belonging to a window is going to get zapped when the document goes away, so you cannot store persistent values in the window object like that because the global object for a web page is recreated each time a page is loaded.

Storing session state data is best accomplished with a frame-set and some accessor scripts that are called within it.

Event handling support via properties containing function objects was added to window objects in version 1.1 of JavaScript.

Warnings:

See also:BODY object, captureEvents(), Collection object, Document object, Document.activeElement, Document.captureEvents(), Document.frames[], Document.parentWindow, Document.releaseEvents(), EventCapturer object, Frame object, Frames object, Global object, IFRAME object, Layer.captureEvents(), Layer.releaseEvents(), Layer.window, self, Window.frame

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
clientInformation n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly, DontEnum.
clipboardData n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
closed1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
crypto1.2 1.2 n/a4.04 4.04 n/a n/a n/a n/a n/a n/a n/aReadOnly.
defaultStatus1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
dialogArguments n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly.
dialogHeight n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
dialogLeft n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
dialogTop n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
dialogWidth n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
document1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning , ReadOnly.
event n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
external n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
frame n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
frameRate1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aReadOnly.
history1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
innerHeight1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aWarning
innerWidth1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aWarning
java1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aReadOnly.
length1.0 1.03.0 3.02.0 2.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aReadOnly.
location1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
locationbar1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
Math1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
menubar1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
name1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning
navigator1.0 1.03.0 3.02.0 2.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
netscape1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aReadOnly.
offScreenBuffering1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
opener1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
outerHeight1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
outerWidth1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
Packages1.1 1.1 n/a3.0 3.0 n/a3.0 3.0 n/a n/a n/a n/a n/aReadOnly.
pageXOffset1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aReadOnly.
pageYOffset1.2 1.2 n/a4.0 4.0 n/a5.0 5.0 n/a n/a n/a n/a n/aReadOnly.
parent1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
personalbar1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
pkcs111.2 1.2 n/a4.04 4.04 n/a n/a n/a n/a n/a n/a n/aReadOnly.
returnValue n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
screen1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
screenLeft n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aReadOnly.
screenTop n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aReadOnly.
screenX1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
screenY1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
scrollbars1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
secure1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aReadOnly.
self1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aReadOnly.
sidebar1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a n/a n/a n/a-
status1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
statusbar1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
sun1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aReadOnly.
toolbar1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , ReadOnly.
top1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.
window1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning , ReadOnly.

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
alert()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
attachEvent() n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aWarning
back()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
blur()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a1 1 n/a n/aWarning
clearInterval()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
clearTimeout()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
close()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
confirm()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/a-
detachEvent() n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
disableExternalCapture()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
enableExternalCapture()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
execScript() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
find()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
focus()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning
forward()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
home()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
moveBy()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
moveTo()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
navigate() n/a1.0 1.0 n/a3.02 3.02 n/a n/a n/a n/a n/a n/aWarning
open()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
print()1.2 1.25.0 5.04.0 4.05.0 5.0 n/a n/a n/a n/a n/a n/aWarning
prompt()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
resizeBy()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
resizeTo()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
scroll()1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning , Deprecated
scrollBy()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
scrollTo()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
setHotkeys()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
setInterval()1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
setResizable()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
setTimeout()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
setZOptions()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
showHelp() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
showModalDialog() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
showModelessDialog() n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
stop()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning

Event nameJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
onAfterPrint n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onBeforePrint n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onBeforeUnload n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onBlur1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning
onDragDrop1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
onError1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning
onFocus1.0 1.03.0 3.02.0 2.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning
onHelp n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
onLoad1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning
onMouseMove1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a4.0 4.0Warning
onMove1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
onResize1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a n/aWarning
onScroll n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onUnload1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aWarning