EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

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

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

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.

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
addEventListener

Registers an event handler for the specified event type.

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 app without prompting the user. To the user, it appears as though the app has crashed.

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.

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.

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.

msIsStaticHTML

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

msWriteProfilerMark

Writes a profiling event.

navigate

Loads the specified URL to the current window.

open

Navigates the app window to the specified location.

postMessage

Sends a cross-document message.

releaseEvents

No appreciable effect. Do not use.

removeEventListener

Removes an event handler that the addEventListener method registered.

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.

toStaticHTML

Removes dynamic HTML elements and attributes from an HTML fragment.

 

Properties

The window object has these properties.

PropertyAccess typeDescription

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.

constructor

Returns a reference to the constructor of an object.

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 a Windows Store app using JavaScript.

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.

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.

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.

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.

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

 

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 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!');">

 

 

Afficher:
© 2014 Microsoft