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.

NoteNote: There is no published standard that applies to the window object, but it is supported by all browsers.


Window object properties

PropertyDescription
closedReturns whether the window has been closed.
defaultStatusSets or returns the default text in the window status bar.
documentA read-only reference to the Document object. (Please refer to DOM Object )
framesReturns all named frames in the window. The collection is an array of Window objects, each Window object containing a frame in the window.
historyA read-only reference to the History object. Please refer to Browser History Object .
innerHeightReturns the height of the window's document display area.
innerWidthReturns the width of the window's document display area.
localStorageStore key/value pairs in the browser. There is no expiration time.
lengthSets or returns the number of frames in the window.
locationLocation object for the window or frame. See Browser Location Object .
nameSets or returns the name of the window.
navigatorA read-only reference to the Navigator object. Please refer to Browser Navigator object .
openerReturns a reference to the window that created this window.
outerHeightReturns the outer height of the window, including toolbars and scroll bars.
outerWidthReturns the outer width of the window, including toolbars and scroll bars.
pageXOffsetSets or returns the X position of the current page relative to the upper left corner of the window display area.
pageYOffsetSets or returns the Y position of the current page relative to the upper left corner of the window display area.
parentReturn to the parent window.
screenA read-only reference to the Screen object. Please refer to Browser Screen object .
screenLeftReturns the x coordinate relative to the screen window
screenTopReturns the y coordinate relative to the screen window
screenXReturns the x coordinate relative to the screen window
sessionStorageStore key/value pairs in the browser. This data will be deleted after closing the window or tab.
screensYReturns the y coordinate relative to the screen window
selfReturns a reference to the current window. Equivalent to the Window property.
statusSets the text for the window status bar.
topReturns the topmost parent window.

Window object methods

MethodDescription
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.