Window Object
Window Object
The Window object represents an open window in the browser.
If the document contains a frame (or
Note: There is no public standard that applies to the window object, but all browsers support it.
Window Object Attributes
| Attribute | Description |
|---|---|
| closed | Returns whether a window has been closed. |
| defaultStatus | Sets or returns the default text in the window's status bar. |
| document | A read-only reference to the Document object. (See Object) |
| frames | Returns all named frames in a window. The collection is an array of Window objects, each Window object containing a frame in the window. |
| history | A read-only reference to the History object. See History Object. |
| innerHeight | Returns the height of the document display area of a window. |
| innerWidth | Returns the width of the document display area of a window. |
| localStorage | Stores key/value pairs in the browser. There is no expiration time. |
| length | Sets or returns the number of frames in a window. |
| location | The Location object for a window or frame. See also Location Object. |
| name | Sets or returns the name of a 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 a window, including toolbars and scrollbars. |
| outerWidth | Returns the outer width of a window, including toolbars and scrollbars. |
| pageXOffset | Sets or returns the X position of the current page relative to the upper-left corner of the window's display area. |
| pageYOffset | Sets or returns the Y position 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 relative to the screen window |
| screenTop | Returns the y-coordinate relative to the screen window |
| screenX | Returns the x-coordinate relative to the screen window |
| sessionStorage | Stores key/value pairs in the browser. This data is deleted after the window or tab is closed. |
| screenY | Returns the y-coordinate relative to the screen window |
| self | Returns a reference to the current window. Equivalent to the Window property. |
| status | Sets the text in the window's status bar. |
| top | Returns the topmost parent window. |
Window Object Methods
| Method | Description |
|---|---|
| alert() | Display an alert box with a message and an OK button. |
| atob() | Decodes a base-64 encoded string. |
| btoa() | Create a base-64 encoded string. |
| blur() | Move the keyboard focus away from the top-level window. |
| clearInterval() | Cancel the timeout set by setInterval(). |
| clearTimeout() | Cancel the timeout set by the setTimeout() method. |
| close() | close the browser window. |
| confirm() | Display a dialog box with a message, an OK button, and a Cancel button. |
| createPopup() | Create a pop-up window. |
| focus() | Give 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 caret. |
| getComputedStyle() | Get the CSS style of a specified element. |
| matchMedia() | This method is used to check a media query statement; it returns a MediaQueryList object. |
| moveBy() | it can be moved by the specified number of pixels relative to the window's current coordinates. |
| moveTo() | Move the upper-left corner of the window to the specified coordinates. |
| open() | Open a new browser window or find a named window. |
| print() | Print the contents of the current window. |
| prompt() | Display a dialog box that can prompt the user for input. |
| resizeBy() | Resize the window by the specified number of pixels. |
| resizeTo() | Resize the window to the specified width and height. |
| scroll() | Deprecated. This method has been replaced by scrollTo() method instead. |
| scrollBy() | Scroll the content by the specified number of pixels. |
| scrollTo() | Scroll the content to the specified coordinates. |
| setInterval() | Call a function or evaluate an expression at the specified interval (in milliseconds). |
| setTimeout() | Call a function or evaluate an expression after the specified number of milliseconds. |
| stop() | Stop page loading. |
| postMessage() | enable cross-origin communication securely. |