WindowObject


Window Object

The Window object represents a window opened in the browser.

If a 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 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 window's status bar.
document A read-only reference to the Document object. (SeeObject)
frames Returns all named frames in the window. This collection is an array of Window objects, each of which contains a frame in the window.
history A read-only reference to the History object. SeeHistory Object。
innerHeight Returns the height of the document display area of the window.
innerWidth Returns the width of the document display area of the window.
localStorage Stores key/value pairs in the browser. No expiration time.
length Sets or returns the number of frames in the window.
location The Location object for the window or frame. SeeLocation Object。
name Sets or returns the name of the window.
navigator A read-only reference to the Navigator object. SeeNavigator 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 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. SeeScreen 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 will be deleted after 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 in the window's status bar.
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() Moves keyboard focus away from the top-level window.
clearInterval() Cancels the timeout set by setInterval().
clearTimeout() Cancels the timeout set by the setTimeout() method.
close() Closes the browser window.
confirm() Displays a dialog box with a message, an OK button, and a Cancel button.
createPopup() Creates 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() Gets the CSS styles of the specified element.
matchMedia() This method is used to check media query statements. It returns a MediaQueryList object.
moveBy() Moves the window by the specified pixels relative to its current coordinates.
moveTo() Moves the upper-left corner of the window to a specified coordinate.
open() Opens a new browser window or finds a named window.
print() Prints the contents of the current window.
prompt() Displays a dialog box that prompts the user for input.
resizeBy() Resizes the window by the specified pixels.
resizeTo() Resizes the window to the specified width and height.
scroll() Deprecated.This method has already been replaced by thescrollTo()method.
scrollBy() Scrolls the content by the specified pixel value.
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 page loading.
postMessage() Safely implements cross-origin communication.
Other Extensions