Window Object
Window object
A 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 published standard that applies to the window object, but it is supported by all browsers.
Window object properties
Property | Description |
---|---|
closed | Returns whether the window has been closed. |
defaultStatus | Sets or returns the default text in the window status bar. |
document | A read-only reference to the Document object. (Please refer to DOM Object ) |
frames | Returns all named frames in the 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. Please refer to Browser 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 | Store key/value pairs in the browser. There is no expiration time. |
length | Sets or returns the number of frames in the window. |
location | Location object for the window or frame. See Browser Location Object . |
name | Sets or returns the name of the window. |
navigator | A read-only reference to the Navigator object. Please refer to Browser Navigator object . |
opener | Returns a reference to the window that created this window. |
outerHeight | Returns the outer height of the window, including toolbars and scroll bars. |
outerWidth | Returns the outer width of the window, including toolbars and scroll bars. |
pageXOffset | Sets or returns the X position of the current page relative to the upper left corner of the window display area. |
pageYOffset | Sets or returns the Y position of the current page relative to the upper left corner of the window display area. |
parent | Return to the parent window. |
screen | A read-only reference to the Screen object. Please refer to Browser 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 | Store key/value pairs in the browser. This data will be deleted after closing the window or tab. |
screensY | 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 for the window status bar. |
top | Returns the topmost parent window. |
Window object methods
Method | Description |
---|---|
alert() | Displays an alert box with a message and a confirmation button. |
atob () | Decode a base-64 encoded string. |
btoa () | Create a base-64 encoded string. |
blur() | Remove the keyboard focus from the top-level window. |
clearInterval() | Cancel the timeout set by setInterval(). |
clearTimeout() | Cancels the timeout set by the setTimeout() method. |
close() | Close the browser window. |
confirm() | Displays a dialog with a message and confirm and cancel buttons. |
createPopup() | Create a pop-up window. |
focus() | Gives keyboard focus to a window. |
getSelection() | Returns a Selection object representing the text range selected by the user or the current position of the cursor. |
getComputedStyle() | Get the CSS style of the specified element. |
matchMedia () | This method is used to check the media query statement, which returns a MediaQueryList object. |
moveBy() | Moves the window by the specified number of pixels relative to its current coordinates. |
moveTo() | Moves the upper-left corner of the window to a specified coordinate. |
open() | Open a new browser window or find a named window. |
print() | Print the contents of the current window. |
prompt() | Displays a dialog that prompts the user for input. |
resizeBy() | Resize the window by the specified pixels. |
resizeTo() | Resize the window to the specified width and height. |
scroll() | Depreciated. This method has been replaced by the scrollTo() method. |
scrollBy() | Scrolls the content by the specified pixel value. |
scrollTo() | Scroll the content to the specified coordinates. |
setInterval() | Calls a function or evaluates an expression at the specified period (in milliseconds). |
setTimeout() | Calls a function or evaluates an expression after the specified number of milliseconds. |
stop() | Stop page loading. |
postMessage() | Securely implement cross-origin communication. |