Window Object
Window Object
The Window object represents an open window in a browser.
If the document contains frames (<frame>
or <iframe>
tags), the browser creates a window object for the HTML document and an additional window object for each frame.
Note: There is no public standard that applies to the Window object, but all browsers support it.
Window Object Properties
Property | Description |
---|---|
closed | Returns whether the window has been closed. |
defaultStatus | Sets or returns the default text in the status bar of a window. |
document | A read-only reference to the Document object. (See Document Object) |
frames | Returns all named frames in the window. This collection is an array of Window objects, each representing a frame in the window. |
history | A read-only reference to the History object. (See History Object) |
innerHeight | Returns the height of the window's document display area. |
innerWidth | Returns the width of the window's document display area. |
localStorage | Stores key/value pairs in the browser with no expiration time. |
length | Sets or returns the number of frames in the window. |
location | The Location object for the window or frame. (See Location Object) |
name | Sets or returns the name of the window. |
navigator | A read-only reference to the Navigator object. (See Navigator Object) |
opener | Returns a reference to the window that created this window. |
outerHeight | Returns the outer height of the window, including toolbars and scrollbars. |
outerWidth | Returns the outer width of the window, including toolbars and scrollbars. |
pageXOffset | Sets or returns the X coordinate of the current page relative to the upper-left corner of the window's display area. |
pageYOffset | Sets or returns the Y coordinate of the current page relative to the upper-left corner of the window's display area. |
parent | Returns the parent window. |
screen | A read-only reference to the Screen object. (See Screen Object) |
screenLeft | Returns the x coordinate of the window relative to the screen. |
screenTop | Returns the y coordinate of the window relative to the screen. |
screenX | Returns the x coordinate of the window relative to the screen. |
sessionStorage | Stores key/value pairs in the browser. These data are deleted when the window or tab is closed. |
screenY | Returns the y coordinate of the window relative to the screen. |
self | Returns a reference to the current window. Equivalent to the Window property. |
status | Sets the text of the status bar of the window. |
top | Returns the topmost parent window. |
Window Object Methods
Method | Description |
---|---|
alert() | Displays an alert box with a message and an OK button. |
atob() | Decodes a base-64 encoded string. |
btoa() | Creates a base-64 encoded string. |
blur() | Removes keyboard focus from the top window. |
clearInterval() | Cancels a timeout set with setInterval(). |
clearTimeout() | Cancels a timeout set with setTimeout(). |
close() | Closes the browser window. |
confirm() | Displays a dialog box with a message and OK and Cancel buttons. |
createPopup() | Creates a pop-up window. |
focus() | Gives keyboard focus to a window. |
getSelection() | Returns a Selection object representing the range of text selected by the user or the current position of the cursor. |
getComputedStyle() | Gets the computed CSS style for the specified element. |
matchMedia() | This method checks the media query statement and returns a MediaQueryList object. |
moveBy() | Moves the window by the specified number of pixels relative to its current coordinates. |
moveTo() | Moves the top-left corner of the window to the specified coordinates. |
open() | Opens a new browser window or finds a named window. |
print() | Prints the content of the current window. |
prompt() | Displays a dialog box prompting the user for input. |
resizeBy() | Resizes the window by the specified number of pixels. |
resizeTo() | Resizes the window to the specified width and height. |
scroll() | Deprecated. This method has been replaced by scrollTo(). |
scrollBy() | Scrolls the content by the specified number of pixels. |
scrollTo() | Scrolls the content to the specified coordinates. |
setInterval() | Calls a function or evaluates an expression at specified intervals (in milliseconds). |
setTimeout() | Calls a function or evaluates an expression after a specified number of milliseconds. |
stop() | Stops the loading of the page. |
postMessage() | Safely enables cross-origin communication. |