English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Window Object

The Window Object (Window Object) represents the window in the browser. The Window Object (Window Object) is automatically created by the browser.

The window is a browser object, not a JavaScript object. JavaScript objects are strings, arrays, dates, etc.

Note:If the HTML document contains frames or iframes, the browser will create other Window Objects (Window Object) for each frame.

All global variables are properties, and functions are methods of the Window Object (Window Object).

ThisDocumentThe object is a property of the Window Object. Therefore, entering

window.document.write("Hello world")

Is equivalent to:

document.write("Hello world")

Window Object (Window Object) Properties

The following table lists the properties of the Window object:

PropertyDescription
closedIndicates whether the current window is closed
consoleReturns a reference to the specified console object, which provides access to the browser's debugging console (See the Console object)
defaultStatusSets or returns the status bar text of the given window
documentReturns a reference to the document contained in the window (See the Document object)
frameElementReturns the <iframe> element that inserted the current window
framesReturns all <iframe> elements in the current window
historyReturns a reference to the history object associated with the window (See the History object)
innerHeightReturns the height of the window content area (viewport) containing the scroll bar
innerWidthReturns the width of the window content area (viewport) containing the scroll bar
lengthReturns the number of <iframe> elements in the current window
localStorageAllows the key/The value pair is stored in the web browser. The data stored without an expiration date
locationReturns a reference to the location object associated with the window (See Location Object)
nameSets or returns the window name
navigatorReturns a reference to the navigator object associated with the window (See Navigator Object)
openerReturns a reference to the window that created the window
outerHeightReturns the height of the browser window, including the toolbar/Scrollbar
outerWidthReturns the width of the browser window, including the toolbar/Scrollbar
pageXOffsetReturns the number of pixels the document has been scrolled horizontally
pageYOffsetReturns the number of pixels the document has been scrolled vertically
parentReturns the parent window of the current window
screenReturns a reference to the screen object associated with the window(See Screen Object)
screenLeftReturns the horizontal coordinate of the window relative to the screen
screenTopReturns the vertical coordinate of the window relative to the screen
screenXscreenLeftalias
screenYscreenTopalias
scrollXpageXOffsetalias
scrollYpageYOffsetalias
sessionStorageAllows the key/Pairs are stored in web browsers. Stores session data
selfReturns a reference to the Window Object (Window Object) itself
statusSets or returns the text in the window status bar
topReturns a reference to the top-level window in the window hierarchy

Window Object (Window Object) Methods

The following table lists the methods of the Window object:

MethodDescription
alert()Displays an alert box with a message and an 'OK' button
atob()Decode base-64Encoded string
blur()Removes the focus from the current window
btoa()In base-64Encode a string
clearInterval()Clears the timer set using setInterval()
clearTimeout()Clears the timer set using setTimeout()
close()Closes the current window
confirm()Displays a dialog box containing a message that the user needs to respond to
focus()Sets the focus to the current window
getComputedStyle()Retrieves the current computed CSS style applied to the element
getSelection()Returns a Selection object representing the text range selected by the user
matchMedia()Returns a MediaQueryList object representing the specified media query string
moveBy()Move the window relative to the current position
moveTo()Move the window to the specified position
open()Open a new browser window
print()Print the content of the current window
prompt()Display a dialog box to prompt the visitor to enter
requestAnimationFrame()Request the browser to call a function to update the animation before the next repaint
resizeBy()Adjust the window size by a specified number of pixels
resizeTo()Adjust the window to the specified width and height
scroll()Not recommended for use.This method has been replaced byscrollTo()Method instead.
scrollBy()Scroll the document by a specified number of pixels
scrollTo()Scroll the document to the specified coordinates
setInterval()Call a function or execute a code block at a specified time interval (in milliseconds)
setTimeout()Call a function or execute a code block after a specified number of milliseconds
stop()Stop Loading Window