Window

O objeto window representa uma janela que contém um elemento DOM; a propriedade document aponta para o documento DOM document (en-US) carregado naquela janela. Uma janela para um dado documento pode ser obtido usando a propriedade document.defaultView.

Esta seção provê uma breve referência a todos os métodos, propriedades e eventos disponíveis através do objeto DOM window. O objeto window implementa a interface Window, o qual herda da interface AbstractView. Algumas funções globais, objeto de namespace, interfaces e construtores, apesar de não tipicamente associados ao objeto em questão, estão disponíveis e estão listados nas referências JavaScript Reference e DOM Reference (en-US).

Em um navegador com suporte a abas, como o Firefox, cada aba contém seu próprio objeto window (e, se você estiver escrevendo uma extensão, a janela do navegador é uma janela distinta também - veja Working with windows in chrome code para mais informação). Isto é, o objeto window não é compartilhado entre as abas na mesma janela. Alguns métodos, nomeadamente window.resizeTo (en-US) e window.resizeBy (en-US) aplicam-se à janela toda e não à aba em questão ao que o objeto window pertence. Geralmente, qualquer coisa que não pode racionalmente pertencer a uma aba, pertence a uma janela..

Propriedades

Esta interface herda propriedades da interface EventTarget e implementa propriedades de WindowTimers, WindowBase64, e WindowEventHandlers.

Perceba que propriedades que são objetos (ex.: sobrecarregar o protótipo de elementos built-in) são listados em uma sessão separada abaixo.

Window.applicationCache Somente leitura

Um objeto OfflineResourceList fornece acesso aos recursos offline para o window.

Window.closed Non-standard Somente leitura

Esta propriedade indica quando a window atual está fechada ou não.

Window.Components Non-standard

O ponto de entrada para muitas características XPCOM. Algumas propriedades, por exemplo, classes, estão apenas disponíveis para código suficientemente privilegiado. Código de Web não deve usar essa propriedade.

Window.console Non-standard Somente leitura

Retorna uma referência para o objeto console fornecendo acesso ao console debugging do navegador.

Window.content (en-US) and Window.content Non-standard Somente leitura

Retorna uma referência para o elemento de conteúdo na janela atual. A variante obsoleta com sublinhado não está disponível a partir do conteúdo da Web.

Window.controllers Non-standard Somente leitura

Retorna os objetos de controlador XUL para a janela atual do crome.

Window.crypto Somente leitura

Retorna o objeto de criptografia do navegador.

Window.defaultStatus

Obtém/define o texto da barra de status para determinada janela.

Window.devicePixelRatio (en-US) Non-standard Somente leitura

Returns the ratio between physical pixels and device independent pixels in the current display.

Window.dialogArguments Somente leitura

Gets the arguments passed to the window (if it's a dialog box) at the time window.showModalDialog() (en-US) was called. This is an nsIArray.

Window.directories

Synonym of window.personalbar (en-US)

Window.document Somente leitura

Retorna a referência à propriedade document que a janela contém.

Window.frameElement (en-US) Somente leitura

Returns the element in which the window is embedded, or null if the window is not embedded.

Window.frames (en-US) Somente leitura

Returns an array of the subframes in the current window.

Window.fullScreen

This property indicates whether the window is displayed in full screen or not.

Window.globalStorage Non-standard

Unsupported since Gecko 13 (Firefox 13). Use Window.localStorage instead. Was: Multiple storage objects that are used for storing data across multiple pages.

Window.history Somente leitura

Retorna a referência ao objeto history.

Window.innerHeight

Gets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.

window.innerWidth (en-US)

Gets the width of the content area of the browser window including, if rendered, the vertical scrollbar.

Window.length Somente leitura

Returns the number of frames in the window. See also window.frames (en-US).

Window.location Somente leitura

Gets/sets the location, or current URL, of the window object.

Window.locationbar (en-US) Somente leitura

Returns the locationbar object, whose visibility can be toggled in the window.

WindowStorage.localStorage Somente leitura

Returns a reference to the local storage object used to store data that may only be accessed by the origin that created it.

Window.menubar (en-US) Somente leitura

Returns the menubar object, whose visibility can be toggled in the window.

Window.messageManager

Returns the message manager object for this window.

Window.mozAnimationStartTime (en-US) Somente leitura

The time in milliseconds since epoch at which the current animation cycle began.

Window.mozInnerScreenX (en-US) Somente leitura Non-standard

Returns the horizontal (X) coordinate of the top-left corner of the window's viewport, in screen coordinates. This value is reported in CSS pixels. See mozScreenPixelsPerCSSPixel in nsIDOMWindowUtils for a conversion factor to adapt to screen pixels if needed.

Window.mozInnerScreenY (en-US) Somente leitura Non-standard

Returns the vertical (Y) coordinate of the top-left corner of the window's viewport, in screen coordinates. This value is reported in CSS pixels. See mozScreenPixelsPerCSSPixel for a conversion factor to adapt to screen pixels if needed.

Window.mozPaintCount (en-US) Non-standard Somente leitura

Returns the number of times the current document has been rendered to the screen in this window. This can be used to compute rendering performance.

Window.name (en-US)

Pega/attribui o nome ao objeto window.

Window.navigator Somente leitura

Returns a reference to the navigator object.

Window.opener (en-US)

Returns a reference to the window that opened this current window.

Window.outerHeight (en-US) Somente leitura

Gets the height of the outside of the browser window.

Window.outerWidth (en-US) Somente leitura

Gets the width of the outside of the browser window.

Window.pageXOffset (en-US) Somente leitura

An alias for window.scrollX (en-US).

Window.pageYOffsetSomente leitura

An alias for window.scrollY

WindowSession.sessionStorage Somente leitura

SpeechSynthesisGetter.speechSynthesis Somente leitura

Window.parent (en-US) Somente leitura

Returns a reference to the parent of the current window or subframe.

Window.performance Somente leitura

Provides a hosting area for performance related (en-US) attributes.

Window.personalbar (en-US) Somente leitura

Returns the personalbar object, whose visibility can be toggled in the window.

Window.pkcs11

Formerly provided access to install and remove PKCS11 modules.

Window.returnValue

The return value to be returned to the function that called window.showModalDialog() (en-US) to display the window as a modal dialog.

Window.screen (en-US) Somente leitura

Returns a reference to the screen object associated with the window.

Window.screenX (en-US) Somente leitura

Returns the horizontal distance of the left border of the user's browser from the left side of the screen.

Window.screenY (en-US) Somente leitura

Returns the vertical distance of the top border of the user's browser from the top side of the screen.

Window.scrollbars (en-US) Somente leitura

Returns the scrollbars object, whose visibility can be toggled in the window.

Window.scrollMaxX (en-US) Non-standard Somente leitura

The maximum offset that the window can be scrolled to horizontally, that is the document width minus the viewport width.

Window.scrollMaxY (en-US) Non-standard Somente leitura

The maximum offset that the window can be scrolled to vertically (i.e., the document height minus the viewport height).

Window.scrollX (en-US) Somente leitura

Returns the number of pixels that the document has already been scrolled horizontally.

Window.scrollY Somente leitura

Returns the number of pixels that the document has already been scrolled vertically.

Window.self (en-US) Somente leitura

Returns an object reference to the window object itself.

Window.sessionStorage

A storage object for storing data within a single page session.

Window.sidebar (en-US) Non-standard Somente leitura

Returns a reference to the window object of the sidebar.

Window.status (en-US)

Gets/sets the text in the statusbar at the bottom of the browser.

Window.statusbar (en-US) Somente leitura

Returns the statusbar object, whose visibility can be toggled in the window.

Window.toolbar (en-US) Somente leitura

Returns the toolbar object, whose visibility can be toggled in the window.

Window.top (en-US) Somente leitura

Returns a reference to the topmost window in the window hierarchy. This property is read only.

Window.window (en-US) Somente leitura

Returns a reference to the current window.

window[0], window[1], etc.

Returns a reference to the window object in the frames. See Window.frames (en-US) for more details.

Methods

This interface inherits methods from the EventTarget interface and implements methods from WindowTimers, WindowBase64, and WindowEventHandlers.

EventTarget.addEventListener()

Register an event handler to a specific event type on the window.

Window.alert()

Displays an alert dialog.

WindowBase64.atob()

Decodes a string of data which has been encoded using base-64 encoding.

Window.back() (en-US) Non-standard

Moves back one in the window history.

Window.blur() (en-US)

Sets focus away from the window.

WindowBase64.btoa() (en-US)

Creates a base-64 encoded ASCII string from a string of binary data.

Window.captureEvents() (en-US) Deprecated

Registers the window to capture all events of the specified type.

Window.clearImmediate() (en-US)

Cancels the repeated execution set using setImmediate.

WindowTimers.clearInterval() (en-US)

Cancels the repeated execution set using WindowTimers.setInterval() (en-US).

WindowTimers.clearTimeout()

Cancels the repeated execution set using WindowTimers.setTimeout() (en-US).

Window.close() (en-US)

Closes the current window.

Window.confirm()

Displays a dialog with a message that the user needs to respond to.

Window.disableExternalCapture()
{{todo("NeedsContents")}}
Window.dispatchEvent()

Used to trigger an event.

Window.dump() (en-US)

Writes a message to the console.

Window.enableExternalCapture()
{{todo("NeedsContents")}}
Window.find() (en-US)

Searches for a given string in a window.

Window.focus() (en-US)

Sets focus on the current window.

Window.forward() (en-US) Non-standard

Moves the window one document forward in the history.

Window.getAttention()

Flashes the application icon.

Window.getAttentionWithCycleCount()
{{todo("NeedsContents")}}
Window.getComputedStyle() (en-US)

Gets computed style for the specified element. Computed style indicates the computed values of all CSS properties of the element.

Window.getDefaulComputedStyle()

Gets default computed style for the specified element, ignoring author stylesheets.

Window.getSelection()

Returns the selection object representing the selected item(s).

Window.home() Non-standard

Returns the browser to the home page.

Window.matchMedia()

Returns a MediaQueryList (en-US) object representing the specified media query string.

Window.maximize()
{{todo("NeedsContents")}}
Window.minimize() (en-US) (top-level XUL windows only)

Minimizes the window.

Window.moveBy() (en-US)

Moves the current window by a specified amount.

Window.moveTo() (en-US)

Moves the window to the specified coordinates.

Window.mozRequestAnimationFrame() (en-US)

Tells the browser that an animation is in progress, requesting that the browser schedule a repaint of the window for the next animation frame. This will cause a MozBeforePaint event to fire before that repaint occurs.

Window.open() (en-US)

Opens a new window.

Window.openDialog()

Opens a new dialog window.

Window.postMessage() (en-US)

Provides a secure means for one window to send a string of data to another window, which need not be within the same domain as the first, in a secure manner.

Window.print()

Opens the Print Dialog to print the current document.

Window.prompt()

Returns the text entered by the user in a prompt dialog.

Window.releaseEvents() (en-US) Deprecated

Releases the window from trapping events of a specific type.

Window.removeEventListener()

Removes an event listener from the window.

Window.resizeBy() (en-US)

Resizes the current window by a certain amount.

Window.resizeTo() (en-US)

Dynamically resizes window.

Window.restore() (en-US)
{{todo("NeedsContents")}}
Window.routeEvent()
{{todo("NeedsContents")}}
Window.scroll()

Scrolls the window to a particular place in the document.

Window.scrollBy()

Scrolls the document in the window by the given amount.

Window.scrollByLines() (en-US)

Scrolls the document by the given number of lines.

Window.scrollByPages()

Scrolls the current document by the specified number of pages.

Window.scrollTo()

Scrolls to a particular set of coordinates in the document.

Window.setCursor()

Changes the cursor for the current window

Window.setImmediate()

Executes a function after the browser has finished other heavy tasks

WindowTimers.setInterval() (en-US)

Schedules the execution of a function each X milliseconds.

Window.setResizable (en-US)
{{todo("NeedsContents")}}
WindowTimers.setTimeout() (en-US)

Sets a delay for executing a function.

Window.showModalDialog() (en-US)

Displays a modal dialog.

Window.sizeToContent() (en-US)

Sizes the window according to its content.

Window.stop() (en-US)

This method stops window loading.

Window.updateCommands() (en-US)

Updates the state of commands of the current chrome window (UI).

Event handlers

These are properties of the window object that can be set to establish event handlers for the various things that can happen in the window that might be of interest.

This interface inherits event handlers from the EventTarget interface and implements event handlers from WindowTimers, WindowBase64, and WindowEventHandlers.

Nota: Starting in Gecko 9.0, you can now use the syntax if ("onabort" in window) to determine whether or not a given event handler property exists. This is because event handler interfaces have been updated to be proper web IDL interfaces. See DOM event handlers (en-US) for details.

GlobalEventHandlers.onabort

An event handler property for abort events on the window.

WindowEventHandlers.onbeforeunload (en-US)

An event handler property for before-unload events on the window.

GlobalEventHandlers.onblur

An event handler property for blur events on the window.

GlobalEventHandlers.onchange

An event handler property for change events on the window.

GlobalEventHandlers.onclick

An event handler property for click events on the window.

GlobalEventHandlers.onclose (en-US)

An event handler property for handling the window close event.

GlobalEventHandlers.oncontextmenu

An event handler property for right-click events on the window.

Window.ondevicelight

An event handler property for any ambient light levels changes

Window.ondevicemotion (en-US)
{{todo("NeedsContents")}}
Window.ondeviceorientation (en-US)

An event handler property for any device orientation changes

Window.ondeviceproximity

An event handler property for device proximity event

GlobalEventHandlers.onerror

An event handler property for error (en-US) events raised on the window.

GlobalEventHandlers.onfocus

An event handler property for focus (en-US) events on the window.

WindowEventHandlers.onhashchange

An event handler property for hash change events on the window; called when the part of the URL after the hash mark ("#") changes.

GlobalEventHandlers.onkeydown (en-US)

An event handler property for keydown (en-US) events on the window.

GlobalEventHandlers.onkeypress (en-US)

An event handler property for keypress (en-US) events on the window.

GlobalEventHandlers.onkeyup

An event handler property for keyup (en-US) events on the window.

WindowEventHandlers.onlanguagechange (en-US)

An event handler property for languagechange (en-US) events on the window.

GlobalEventHandlers.onload

An event handler property for window loading.

GlobalEventHandlers.onmousedown (en-US)

An event handler property for mousedown events on the window.

GlobalEventHandlers.onmousemove (en-US)

An event handler property for mousemove events on the window.

GlobalEventHandlers.onmouseout (en-US)

An event handler property for mouseout events on the window.

GlobalEventHandlers.onmouseover (en-US)

An event handler property for mouseover events on the window.

GlobalEventHandlers.onmouseup (en-US)

An event handler property for mouseup events on the window.

Window.onmozbeforepaint

An event handler property for the MozBeforePaint event, which is sent before repainting the window if the event has been requested by a call to the Window.mozRequestAnimationFrame() (en-US) method.

WindowEventHandlers.onpageshow

An event handler property for pageshow events on the window.

WindowEventHandlers.onpagehide

An event handler property for pagehide events on the window.

Window.onpaint

An event handler property for paint events on the window.

WindowEventHandlers.onpopstate

An event handler property for popstate events, which are fired when navigating to a session history entry representing a state object.

GlobalEventHandlers.onreset (en-US)

An event handler property for reset events on the window.

GlobalEventHandlers.onresize (en-US)

An event handler property for window resizing.

GlobalEventHandlers.onscroll

An event handler property for window scrolling.

GlobalEventHandlers.onselect (en-US)

An event handler property for window selection.

GlobalEventHandlers.onsubmit (en-US)

An event handler property for submits on window forms.

Window.onunload (en-US)

An event handler property for unload events on the window.

Window.onuserproximity

An event handler property for user proximity events

Constructors

See also the DOM Interfaces (en-US).

Window.DOMParser
{{todo("NeedsContents")}}
Window.GeckoActiveXObject
{{todo("NeedsContents")}}
Image (en-US)

Used for creating an HTMLImageElement (en-US).

Option (en-US)

Used for creating an HTMLOptionElement (en-US)

Window.QueryInterface
{{todo("NeedsContents")}}
Window.XMLSerializer
{{todo("NeedsContents")}}
Worker

Used for creating a Web worker (en-US)

Window.XPCNativeWrapper
{{todo("NeedsContents")}}
Window.XPCSafeJSObjectWrapper
{{todo("NeedsContents")}}

Interfaces

See also