Export (0) Print
Expand All
80 out of 190 rated this helpful - Rate this topic

window object

Represents an open window.

Members

The window object has these types of members:

Events

The window object has these events.

EventDescription
click

Fires when the user clicks the left mouse button on the object.

Note  Starting with IE11, this event fires a MSPointerEvent object instead of MouseEvent. You can use the MouseEvent.pointerType property to determine the type of contact that the click originated from (touch, mouse, or pen).

abort

Fires when the user aborts the download.

afterprint

Fires on the object immediately after its associated document prints or previews for printing.

beforeprint

Fires on the object before its associated document prints or previews for printing.

beforeunload

Fires prior to a document being unloaded.

blur

Fires when the object loses the input focus.

canplay

Occurs when playback is possible, but would require further buffering.

canplaythrough

Occurs when playback to end is possible without requiring a stop for further buffering.

change

Fires when the contents of the object or selection have changed.

compassneedscalibration

Fires whenever the device magnetometer changes to a state of unreliable or approximate accuracy.

contextmenu

Fires when the user clicks the right mouse button in the client area, opening the context menu.

Note  Starting with IE11, this event fires a MSPointerEvent object instead of MouseEvent. You can use the MouseEvent.pointerType property to determine the type of contact that the click originated from (touch, mouse, or pen).

dblclick

Fires when the user double-clicks the object.

Note  Starting with IE11, this event fires a MSPointerEvent object instead of a MouseEvent. You can use the MouseEvent.pointerType property to determine the type of contact that the click originated from (touch, mouse, or pen).

drag

Fires on the source object continuously during a drag operation.

dragend

Fires on the source object when the user releases the mouse at the close of a drag operation.

dragenter

Fires on the target element when the user drags the object to a valid drop target.

dragleave

Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation.

dragover

Fires on the target element continuously while the user drags the object over a valid drop target.

dragstart

Fires on the source object when the user starts to drag a text selection or selected object.

drop

Fires on the target object when the mouse button is released during a drag-and-drop operation.

durationchange

Occurs when the duration attribute is updated.

emptied

Occurs when the media element is reset to its initial state.

ended

Occurs when the end of playback is reached.

error

Fires when an error occurs during object loading.

focus

Fires when the object receives focus.

focusin

Fires for an element just prior to setting focus on that element.

focusout

Fires for the current element with focus immediately after moving focus to another element.

gotpointercapture

Dispatched prior to the dispatch of the first event after pointer capture is set for a pointer.

hashchange

Raised when there are changes to the portion of a URL that follows the number sign (#).

This event is not supported for Windows Store apps using JavaScript.

help

Fires when the user presses the F1 key while the client is the active window.

input

Occurs when the text content of an element is changed through the user interface.

keydown

Fires when the user presses a key.

keypress

Fires when the user presses an alphanumeric key.

load

Fires immediately after the client loads the object.

loadeddata

Occurs when media data is loaded at the current playback position.

loadedmetadata

Occurs when the duration and dimensions of the media have been determined.

loadstart

Occurs when Internet Explorer begins looking for media data.

lostpointercapture

Dispatched after pointer capture is released for a pointer.

message

Fires when the user sends a cross-document message or a message is sent from a Worker with postMessage.

mousedown

Fires when the user clicks the object with either mouse button.

mousemove

Fires when the user moves the mouse over the object.

mouseout

Fires when the user moves the mouse pointer outside the boundaries of the object.

mouseover

Fires when the user moves the mouse pointer into the object.

mouseup

Fires when the user releases a mouse button while the mouse is over the object.

mousewheel

Fires when the wheel button is rotated.

MSPointerHover

Event that is triggered when a contact (normally a pen) moves over an element without touching the surface.

offline

Raised when Internet Explorer is working offline.

This event is not supported for Windows Store apps using JavaScript.

onbeforedeactivate

Fires immediately before the activeElement is changed from the current object to another object in the parent document.

onkeyup

Fires when the user releases a key.

online

Raised when Internet Explorer is working online.

This event is not supported for Windows Store apps using JavaScript.

onselect

Fires when the current selection changes.

pause

Occurs when playback is paused.

play

Occurs when the play method is requested.

playing

Occurs when the audio or video has started playing.

pointercancel

Dispatched when either (1) the system has determined that a pointer is unlikely to continue to produce events (for example, due to a hardware event), or (2) after having fired the pointerdown event, the pointer is subsequently used to manipulate the page viewport (for example, panning or zooming).

pointerdown

Dispatched when a pointer enters the state of having a non-zero value for the buttons property.

pointerenter

Dispatched when a pointing device is moved into the hit test boundaries of an element or one of its descendants, including as a result of a pointerdown event from a device that does not support hover.

pointerleave

Dispatched when a pointing device is moved outside of the hit test boundaries of an element or one of its descendants, including as a result of a pointerdown event from a device that does not support hover.

pointermove

Dispatched when a pointer changes coordinates, button state, pressure, tilt, or contact geometry (for example, width and height).

pointerout

Dispatched when any of the following occurs:

  • A pointing device is moved out of the hit test boundaries of an element
  • After firing the pointerup event for a device that does not support hover
  • After firing the pointercancel event
pointerover

Dispatched when a pointing device is moved into the hit test boundaries of an element. Also dispatched prior to a pointerdown event for devices that do not support hover.

pointerup

Dispatched when a pointer leaves the state of having a non-zero value for the buttons property.

progress

Occurs to indicate progress while downloading media data.

ratechange

Occurs when the playback rate is increased or decreased.

reset

Fires when the user resets a form.

scroll

Fires when the user repositions the scroll box in the scroll bar on the object.

seeked

Occurs when the seek operation ends.

seeking

Occurs when the current playback position is moved.

stalled

Occurs when the download has stopped.

storage

Fires when a Web Storage area is updated.

suspend

Occurs if the load operation has been intentionally halted.

timeupdate

Occurs to indicate the current playback position.

unload

Fires immediately before the object is unloaded.

volumechange

Occurs when the volume is changed, or playback is muted or unmuted.

waiting

Occurs when playback stops because the next frame of a video resource is not available.

 

Methods

The window object has these methods.

MethodDescription
AddChannel

Obsolete. Presents a dialog box that enables the user to add the specified channel, or to change the channel URL, if it is already installed.

addEventListener

Registers an event handler for the specified event type.

AddSearchProvider

Deprecated. Adds a search provider to the registry.

AddService

Deprecated. User initiated action to add a service.

AddToFavoritesBar

Deprecated. Adds a URL to the Favorites Bar.

alert

Displays a dialog box containing an application-defined message.

This method is not supported for Windows Store apps using JavaScript.

attachEvent

Note   attachEvent is no longer supported. Starting with IE11, use addEventListener. For info, see Compatibility changes.

Binds the specified function to an event, so that the function gets called whenever the event fires on the object.

blur

Causes the element to lose focus and fires the onblur event.

captureEvents

No appreciable effect. Do not use.

clearImmediate

Cancels a function request created with setImmediate.

clearInterval

Cancels the interval previously started using the setInterval method.

clearTimeout

Cancels a time-out that was set with the setTimeout method.

close

Closes the current browser window or HTA.

Closes the app without prompting the user. To the user, it appears as though the app has crashed.

confirm

Displays a confirmation dialog box that contains an optional message as well as OK and Cancel buttons.

This method is not supported for Windows Store apps using JavaScript.

ContentDiscoveryReset

Resets the list of feeds, search providers, and Web Slices associated with the page.

create

Creates a new img element of the specified width and height. This method cannot be called directly. See Image object.

create

Initializes a new option element. This method cannot be called directly. See Option object.

createPopup

Note   createPopup is no longer supported. Starting with IE11, use a div, iframe, or other element with a relatively high z-index value. For info, see Compatibility changes.

Creates a popup window object.

detachEvent

Unbinds the specified function from the event, so that the function stops receiving notifications when the event fires.

dispatchEvent

Sends an event to the current element.

execScript

Note   execScript is no longer supported. Starting with IE11, use eval. For info, see Compatibility changes.

Executes the specified script in the provided language.

focus

Causes the element to receive the focus and executes the code specified by the onfocus event.

getComputedStyle

Returns a currentStyle object containing the CSS settings that are applied to the specified element or a pseudo-element related to the specified element.

getSelection

Returns an object that represents the current selection of the document.

InPrivateFilteringEnabled

Detects whether the user has enabled InPrivate Filtering.

IsSearchProviderInstalled

Deprecated. Determines if a search provider has been installed for the current user and whether it is set as default.

IsServiceInstalled

Deprecated. Check if a service is already installed.

item

Retrieves an object from various collections, including the all collection.

matchMedia

Accepts a string containing one or more media queries, and returns a MediaQueryList object.

moveBy

Moves the screen position of the window by the specified x and y offset values.

moveTo

Moves the screen position of the upper-left corner of the window to the specified x and y position.

msActiveXFilteringEnabled

Determines whether ActiveX Filtering is enabled by the user.

msAddSiteMode

Creates a pinned site shortcut to the current webpage on the Windows Start menu.

This method is not supported for Windows Store apps using JavaScript.

msAddTrackingProtectionList

Adds an external Tracking Protection list.

msIsSiteMode

Determines whether the current page was launched as a pinned site.

msIsSiteModeFirstRun

Determines whether a pinned site was launched for the first time.

msIsStaticHTML

Returns a Boolean value indicating whether or not the given HTML string is safe.

msSiteModeActivate

Flashes the pinned site taskbar button.

This method is not supported for Windows Store apps using JavaScript.

msSiteModeAddButtonStyle

Defines an alternate icon image and tooltip for the specified button.

This method is not supported for Windows Store apps using JavaScript.

msSiteModeAddJumpListItem

Adds a new entry to the Jump List of a taskbar button.

msSiteModeAddThumbBarButton

Adds a button to the Thumbnail Toolbar.

This method is not supported for Windows Store apps using JavaScript.

msSiteModeClearIconOverlay

Removes the icon overlay from the taskbar button.

This method is not supported for Windows Store apps using JavaScript.

msSiteModeClearJumpList

Deletes the Jump List.

msSiteModeCreateJumpList

Creates a new group of items on the Jump List.

msSiteModeSetIconOverlay

Adds an icon overlay to the pinned site taskbar button.

This method is not supported for Windows Store apps using JavaScript.

msSiteModeShowButtonStyle

Changes the icon image and tooltip of a Thumbnail Toolbar button.

This method is not supported for Windows Store apps using JavaScript.

msSiteModeShowJumpList

Shows updates to the list of items in a Jump List.

msSiteModeShowThumbBar

Enables the Thumbnail Toolbar in the thumbnail preview of a pinned site.

This method is not supported for Windows Store apps using JavaScript.

msSiteModeUpdateThumbBarButton

Changes the state of a Thumbnail Toolbar button.

This method is not supported for Windows Store apps using JavaScript.

msTrackingProtectionEnabled

Determines whether any Tracking Protection lists are enabled by the user.

msWriteProfilerMark

Writes a profiling event.

navigate

Loads the specified URL to the current window.

open

Opens a new window and loads the document specified by a given URL.

Navigates the app window to the specified location.

postMessage

Sends a cross-document message.

print

Prints the document associated with the window.

prompt

Displays a dialog box that prompts the user with a message and an input field.

releaseEvents

No appreciable effect. Do not use.

removeEventListener

Removes an event handler that the addEventListener method registered.

resizeBy

Changes the current size of the window by the specified x- and y-offset.

resizeTo

Sets the size of the window to the specified width and height values.

scroll

Causes the window to scroll to the specified x- and y-offset at the upper-left corner of the window.

scrollBy

Causes the window to scroll relative to the current scrolled position by the specified x- and y-pixel offset.

scrollTo

Scrolls the window to the specified x- and y-offset.

setImmediate

Requests that a function be called when current or pending tasks are complete, such as events or screen updates.

setInterval

Evaluates an expression each time a specified number of milliseconds has elapsed.

setTimeout

Evaluates an expression after a specified number of milliseconds has elapsed.

showHelp

Displays a Help file. This method can be used with Microsoft HTML Help.

showModalDialog

Creates a modal dialog box that displays the specified HTML document.

showModelessDialog

Creates a modeless dialog box that displays the specified HTML document.

toStaticHTML

Removes dynamic HTML elements and attributes from an HTML fragment.

 

Properties

The window object has these properties.

PropertyAccess typeDescription

ActiveXObject

Returns a null value.

animationStartTime

Read-only

Obsolete. Returns a timestamp of the start time of the current refresh interval, such that multiple animations can be synchronized with each other.

applicationCache

Read-only

Returns an ApplicationCache object.

closed

Retrieves whether the referenced window is closed.

console

Read-only

Returns the windows console object to use to send messages.

constructor

Returns a reference to the constructor of an object.

defaultStatus

Sets or retrieves the default message displayed in the status bar at the bottom of the window.

dialogArguments

Gets the variable or array of variables passed into the modal dialog window.

dialogHeight

Sets or gets the height of the modal dialog window.

dialogLeft

Sets or gets the left coordinate of the modal dialog window.

dialogTop

Sets or gets the top coordinate of the modal dialog window.

dialogWidth

Sets or gets the width of the modal dialog window.

frameElement

Retrieves the frame or iframe object that is hosting the window in the parent document.

hidden

Read-only

Returns whether a webpage is visible.

indexedDB

Read-only

Allows access to the Indexed Database API, as implemented by Internet Explorer 10.

innerHeight

Gets the height of the window, excluding user interface elements, such as the window frame, toolbars, and so on.

innerWidth

Gets the width of the window, excluding user interface elements, such as the window frame.

length

Sets or retrieves the number of objects in a collection.

localStorage

Retrieves the Web Storage area specific to the current document.

maxConnectionsPerServer

Retrieves the maximum number of concurrent connections to a Web server.

msCrypto

Read-only

Property providing the Web Cryptography methods and properties.

name

Sets or retrieves a value that indicates the window name.

offscreenBuffering

Sets or retrieves whether objects are drawn offscreen before being made visible to the user.

opener

Sets or retrieves a reference to the window that created the current window.

outerHeight

Gets the height of the window, including user interface elements, such as the window frame, toolbars, and so on.

outerWidth

Gets the width of the window, including user interface elements, such as the window frame.

pageXOffset

Gets the distance, in pixels, that a document has scrolled horizontally.

pageYOffset

Gets the distance, in pixels, that a document has scrolled vertically.

parent

Retrieves the parent of the window in the object hierarchy.

performance

Provides access to timing related information regarding navigation and performance for the document that is loaded into the window object.

returnValue

Sets or gets the value returned from the modal dialog window.

This property is not supported for Windows Store apps using JavaScript.

screenLeft

Retrieves the x-coordinate of the upper left-hand corner of the window frame, relative to the upper left-hand corner of the screen.

screenTop

Retrieves the y-coordinate of the top corner of the client area, relative to the top corner of the screen.

screenX

Sets or retrieves the x-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenX.

screenY

Sets or retrieves the y-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenY.

self

Retrieves a reference to the current window or frame.

sessionStorage

Retrieves the Web Storage area for the session.

status

Sets or retrieves the message in the status bar at the bottom of the window.

styleMedia

Gets a StyleMedia object that contains methods and properties. These methods and properties determine the media types that are supported by the object that displays the document object.

top

Retrieves the topmost ancestor window.

XMLHttpRequest

Instantiates the XMLHttpRequest object for the window.

 

Standards information

There are no standards that apply here.

Remarks

You can use the window object to retrieve information about the state of the window. You also can use this object to gain access to the document in the window, to the events that occur in the window, and to other factors that affect the window.

You can apply any window property, method, or collection to any variable or expression that evaluates to a window object, regardless of how that window was created. Additionally, you can access all window properties, methods, and collections in the current window by using the property, method, or collection name directly—that is, without prefixing it with an expression that evaluates to the current window object. However, to help make more readable code and to avoid potential ambiguities, many authors use the window keyword when accessing window properties, methods, and collections for the current window. This keyword always refers to the current window.

Note  The window's properties, methods, and collection names are reserved keywords and cannot be used as the names of variables or routines.

The following table lists pertinent information for some of the properties of the window object.

PropertyMethodDescription
opener open The opener property is available only from a document opened using the window.open method.
parent, top NoneThe parent and top properties are available for a window opened inside a frame or iframe. The two properties return the topmost parent and immediate parent, respectively.
parent, top open The parent and top properties are available for a window opened via the open method or as a dialog and returns the current window.
length NoneRegardless of how the window is opened, the length property returns the number of frames in a window.
dialogArguments, dialogHeight, dialogLeft, dialogTop, dialogWidth, returnValue showModalDialog and showModelessDialog These properties are available only for windows created using the two methods listed—showModalDialog and showModelessDialog

 

Typically, the browser creates one window object when it opens an HTML document. However, if a document defines one or more frames (that is, contains one or more frame or iframe tags), the browser creates one window object for the original document and one additional window object for each frame. These additional objects are of the original window and can be affected by actions that occur in the original. For example, closing the original window causes all child windows to close. You can also create new windows (and corresponding window objects) using methods such as open, showModalDialog, and showModelessDialog.

Unsupported window members for Windows Store apps using JavaScript

These window members are unavailable to Windows Store apps using JavaScript:

In Windows CE, the document object is not available through scripting for a window object opened using the open method.

Examples

This example checks whether the current window contains child windows and, if it does, displays the names of those child windows in a debugging console window (see F12 Developer Tools for more information).


if ( window.frames != null ) {
    for ( i = 0; i < window.frames.length; i++ )
        console.log("Child window " + i + " is named " + window.frames(i).name);
}

This example shows a simple event handler function for the window's onload event. In the absence of a "window" element, the body element hosts the following window object events: onblur, onbeforeunload, onfocus, onload, and onunload.


<body onload="console.log('Document is loaded!');">

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.