window
El objeto window
representa la ventana que contiene un documento DOM; la propiedad document
apunta al DOM document cargado en esa ventana. El objeto window al que pertenece un documento puede ser obtenido usando la propiedad document.defaultView
.
Esta sección proporciona una pequeña referencia a todos los métodos, propiedades y eventos disponibles a través del objeto DOM window
. El objeto window
implementa la interfaz Window
, que a su vez hereda de la interfaz AbstractView
. Algunas funciones como globales adicionales, espacios de nombres, interfaces, y constructores no típicamente asociados con el objeto window pero disponibles en éste, están listados en las Referencia de JavaScript y en el Referencia DOM de Gecko.
En un navegador con pestañas, como Firefox, cada pestaña contine su propio window
object (y si está escribiendo una extensión, la ventana del navegador es una ventana separada también - para más información vea Trabajar con ventanas desde el código chrome). Esto significa que el objeto window
no se comparte entre diferentes pestañas de la misma ventana del navegador. Algunos métodos, como window.resizeTo
y window.resizeBy
se aplican sobre toda la ventana del navegador y no sobre una pestaña específica a la que pertenece el objeto window
. Generalmente, cualquier cosa que razonablemente no pueda pertenecer a una pestaña, pertenece a la ventana.
Constructores
Ver también DOM Interfaces.
Window.DOMParser
-
DOMParser
puede traducir una fuente XML o HTML almacenada en una cadena en un Documento DOM.DOMParser
se especifica en DOM Parsing and Serialization. Image
-
Se usa para crear un
HTMLImageElement
. Option
-
Se usa para crear un
HTMLOptionElement
StaticRange
Experimental Read only-
Retorna un constructor
StaticRange()
que crea un objetoStaticRange
.
Worker
-
Se usa para crear un Web worker.
Window.XMLSerializer
-
Convierte un árbol DOM en una fuente XML o HTML.
Propiedades
Esta interface hereda propiedades de EventTarget
interface e implementa propiedades de WindowTimers
y WindowBase64
.
Nota que la propiedades que son objetos (por ejemplo para sobreescribir los prototipos de los elementos built-in) son descritos en una sección separada más abajo.
Window.applicationCache
Read only-
An
OfflineResourceList
object providing access to the offline resources for the window. Window.closed
Non-standard Read only-
Esta propiedad indica si la actual ventana esta cerrada o abierta.
Window.Components
Non-standard-
El punto de acceso a muchas propiedades XPCOM. Algunas propiedades, ej. classes, son disponibles solamente a codigo suficientemente privilegiado. El codigo Web no deberia usar esta propiedad.
Window.console
Non-standard Read only-
Retorna una referencia al objeto de la consola proveyendo acceso a la consola debugger del navegador.
Window.content
and Window.content Non-standard Obsoleto Read only-
Returns a reference to the content element in the current window. The obsolete variant with underscore is no longer available from Web content.
Window.controllers
Non-standard Read only-
Returns the XUL controller objects for the current chrome window.
Window.crypto
Read only-
Returns the browser crypto object.
Window.defaultStatus
Obsoleto-
Gets/sets the status bar text for the given window.
Window.devicePixelRatio
Non-standard Read only-
Returns the ratio between physical pixels and device independent pixels in the current display.
Window.dialogArguments
Read only-
Gets the arguments passed to the window (if it's a dialog box) at the time
window.showModalDialog()
was called. This is annsIArray
. Window.directories
Obsoleto-
Sinonimo de
window.personalbar
Window.document
Read only-
Retorna una referencia al documento que esa ventana contiene.
Window.frameElement
Read only-
Returns the element in which the window is embedded, or null if the window is not embedded.
Window.frames
Read only-
Returns an array of the subframes in the current window.
Window.fullScreen
-
Esta propiedad indica si la ventana esta desplegada en pantalla completa o no.
Non-standard Obsoletowindow.globalStorage
-
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
Read only-
Retorna una referencia a la historia del objeto.
Window.innerHeight
-
Obtiene la altura del area de contenido del navegador incluyendo, si es interpretado, la barra de deslizado.
window.innerWidth
-
Obtiene el ancho del area de contenido de la ventana del navegador, si es interpretado, la barra de deslizado vertical.
Window.length
Read only-
Retorna el numero de marcos en la ventana. Ver tambien
window.frames
. Window.location
Read only-
Obtiene/fija la location, o URL actual, del objeto de la ventana.
Window.locationbar
Read only-
Retorna el objeto locationbar, cuya visibilidad puede ser fijada en la ventana.
Window.localStorage
Read only-
Retorna una referencia al objeto almacenamiento local usado para almacenar datos que pueden ser de accedidos por el origen que los creo.
-
Retorna el objeto barra de menu, cuya visibilidad puede ser fijada en la ventana.
Window.messageManager
-
Retorna el objeto message manager para esta ventana.
Window.mozAnimationStartTime
Read only-
The time in milliseconds since epoch at which the current animation cycle began.
Window.mozInnerScreenX
Read only 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
innsIDOMWindowUtils
for a conversion factor to adapt to screen pixels if needed. Window.mozInnerScreenY
Read only 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
Non-standard Read only-
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
-
Gets/sets the name of the window.
-
Returns a reference to the navigator object.
Window.opener
-
Returns a reference to the window that opened this current window.
Window.outerHeight
Read only-
Gets the height of the outside of the browser window.
Window.outerWidth
Read only-
Gets the width of the outside of the browser window.
Window.pageXOffset
Read only-
An alias for
window.scrollX
. Window.pageYOffset
Read only-
An alias for
window.scrollY
Window.sessionStorage
Read only-
Returns a reference to the session storage object used to store data that may only be accessed by the origin that created it.
SpeechSynthesisGetter.speechSynthesis
Read only-
Returns a
SpeechSynthesis
object, which is the entry point into using Web Speech API speech synthesis functionality. Window.parent
Read only-
Returns a reference to the parent of the current window or subframe.
Window.performance
Read only-
Provides a hosting area for performance related attributes.
Window.personalbar
Read only-
Returns the personalbar object, whose visibility can be toggled in the window.
Window.pkcs11
Obsoleto-
Formerly provided access to install and remove PKCS11 modules.
Window.returnValue
-
The return value to be returned to the function that called
window.showModalDialog()
to display the window as a modal dialog. Window.screen
Read only-
Returns a reference to the screen object associated with the window.
Window.screenX
Read only-
Returns the horizontal distance of the left border of the user's browser from the left side of the screen.
Window.screenY
Read only-
Returns the vertical distance of the top border of the user's browser from the top side of the screen.
Window.scrollbars
Read only-
Returns the scrollbars object, whose visibility can be toggled in the window.
Window.scrollMaxX
Non-standard Read only-
The maximum offset that the window can be scrolled to horizontally, that is the document width minus the viewport width.
Window.scrollMaxY
Non-standard Read only-
The maximum offset that the window can be scrolled to vertically (i.e., the document height minus the viewport height).
Window.scrollX
Read only-
Returns the number of pixels that the document has already been scrolled horizontally.
Window.scrollY
Read only-
Returns the number of pixels that the document has already been scrolled vertically.
Window.self
Read only-
Returns an object reference to the window object itself.
Window.sessionStorage
-
Returns a storage object for storing data within a single page session.
-
Returns a reference to the window object of the sidebar.
Window.status
-
Gets/sets the text in the statusbar at the bottom of the browser.
Window.statusbar
Read only-
Returns the statusbar object, whose visibility can be toggled in the window.
Window.toolbar
Read only-
Returns the toolbar object, whose visibility can be toggled in the window.
Window.top
Read only-
Returns a reference to the topmost window in the window hierarchy. This property is read only.
Window.window
Read only-
Returns a reference to the current window.
window[0]
,window[1]
, etc.-
Returns a reference to the
window
object in the frames. SeeWindow.frames
for more details.
Methods
Esta interfaz hereda metodos de la interfaz EventTarget
e implementa metodos WindowTimers
y WindowBase64
.
EventTarget.addEventListener()
-
Registra un controlador de eventos a un tipo de evento especifico en la ventana.
Window.alert()
-
Muestra una pequeña ventana de alerta. El estilo y posición de la ventana puede variar dependiendo de que navegador este usando.
WindowBase64.atob()
-
Decodes a string of data which has been encoded using base-64 encoding.
Window.back()
Non-standard Obsoleto-
Regresa en la ventana de historial.
Window.blur()
-
Sets focus away from the window.
WindowBase64.btoa()
-
Creates a base-64 encoded ASCII string from a string of binary data.
Window.captureEvents()
Obsoleto-
Registers the window to capture all events of the specified type.
Window.clearImmediate()
-
Cancels the repeated execution set using
setImmediate
. WindowTimers.clearInterval()
-
Cancels the repeated execution set using
WindowTimers.setInterval()
. WindowTimers.clearTimeout()
-
Cancels the repeated execution set using
WindowTimers.setTimeout()
. Window.close()
-
Cierra la ventana actual.
Window.confirm()
-
Muestra una ventana de comfirmación con dos únicas y posibles respuestas. Confirmar y Cancelar.
Window.disableExternalCapture()
ObsoletoWindow.dispatchEvent()
-
Usado para activar un evento.
Window.dump()
-
Escribe un mensaje a la consola.
Window.enableExternalCapture()
ObsoletoWindow.find()
-
Busca un string dado en una ventana.
Window.focus()
-
Fija el enfoque en la ventana actual.
Window.forward()
Non-standard Obsoleto-
Moves the window one document forward in the history.
Window.getAttention()
-
Flashes the application icon.
Window.getAttentionWithCycleCount()
Window.getComputedStyle()
-
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 Obsoleto-
Regresa el navegador a la pagina de inicio.
Window.matchMedia()
-
Returns a
MediaQueryList
object representing the specified media query string. Window.maximize()
Window.minimize()
(top-level XUL windows only)-
Minimiza la ventana.
Window.moveBy()
-
Mueve la ventana actual por una cantidad especificada.
Window.moveTo()
-
Mueve la ventana a una coordenada especificada.
Window.mozRequestAnimationFrame()
-
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()
-
Abre una nueva ventana.
Window.openDialog()
-
Abre una nueva ventana de dialogo.
Window.postMessage()
-
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.
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()
Obsoleto-
Releases the window from trapping events of a specific type.
Window.removeEventListener()
-
Removes an event listener from the window.
Window.resizeBy()
-
Resizes the current window by a certain amount.
Window.resizeTo()
-
Dynamically resizes window.
Window.restore()
Window.routeEvent()
ObsoletoWindow.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()
-
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()
-
Schedules the execution of a function each X milliseconds.
Window.setResizable
WindowTimers.setTimeout()
-
Sets a delay for executing a function.
Window.showModalDialog()
-
Displays a modal dialog.
Window.sizeToContent()
-
Sizes the window according to its content.
Window.stop()
-
This method stops window loading.
Window.updateCommands()
-
Updates the state of commands of the current chrome window (UI).
Eventos
Estas son propiedades del objeto ventana que pueden ser fijadas para establecer controladores de eventos para las diversar cosas que pueden pasar en la ventana que podria ser de interes.
Esta interfaz hereda controladores de eventos de la interfaz EventTarget
e implementa controladores de eventos desde WindowTimers
y WindowBase64
.
Nota: Empezando en Gecko 9.0, se puede usar el sintaxis if ("onabort" in window)
para determinar si existe una propiedad dada de controlador de eventos o no. Esto es porque interfazes de controlador de eventos han sido actualizadas al respectivo web IDL interfaz. Ver DOM event handlers para mas detalles.
GlobalEventHandlers.onabort
-
An event handler property for abort events on the window.
beforeunload
-
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
-
An event handler property for handling the window close event.
-
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
Window.ondeviceorientation
-
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
events raised on the window. GlobalEventHandlers.onfocus
-
An event handler property for
focus
events on the window. hashchange
-
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
-
An event handler property for
keydown
events on the window. GlobalEventHandlers.onkeypress
-
An event handler property for
keypress
events on the window. GlobalEventHandlers.onkeyup
-
An event handler property for
keyup
events on the window. languagechange
-
An event handler property for
languagechange
events on the window. GlobalEventHandlers.onload
-
An event handler property for window loading.
GlobalEventHandlers.onmousedown
-
An event handler property for mousedown events on the window.
GlobalEventHandlers.onmousemove
-
An event handler property for mousemove events on the window.
GlobalEventHandlers.onmouseout
-
An event handler property for mouseout events on the window.
GlobalEventHandlers.onmouseover
-
An event handler property for mouseover events on the window.
GlobalEventHandlers.onmouseup
-
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 theWindow.mozRequestAnimationFrame()
method. pageshow
-
An event handler property for pageshow events on the window.
pagehide
-
An event handler property for pagehide events on the window.
Window.onpaint
-
An event handler property for paint events on the window.
popstate
-
An event handler property for popstate events, which are fired when navigating to a session history entry representing a state object.
GlobalEventHandlers.onreset
-
An event handler property for reset events on the window.
GlobalEventHandlers.onresize
-
An event handler property for window resizing.
GlobalEventHandlers.onscroll
-
An event handler property for window scrolling.
GlobalEventHandlers.onselect
-
An event handler property for window selection.
GlobalEventHandlers.onsubmit
-
An event handler property for submits on window forms.
Window.onunload
-
An event handler property for unload events on the window.
Window.onuserproximity
-
An event handler property for user proximity events
Interfaces
Ver DOM Reference