HTML CSS Bootstrap Javascript Icons Python
JavaScript Reference
Overview
JS Reference
JS Array Object JS Boolean Object JS Date Object JS Style Declaration Object JS Error Object JS Global Object JS Math Object JS Number Object JS String Object JS RegExp Object JS Statements
DOM Reference
DOM Attribute DOM Console DOM Document DOM Element DOM Events DOM Event Objects DOM History DOM HTMLCollection DOM Location DOM Navigator DOM Screen DOM Style DOM Window WEB Storage

The Window Object

The window object represents a window in browser. An object of window is created automatically by the browser.

Window is the object of browser, it is not the object of javascript. The javascript objects are string, array, date etc.

Note: If html document contains frame or iframe, browser creates additional window objects for each frame.

All global variables are properties and functions are methods of the window object.

The document object is a property of the window object. So, typing

window.document.write("Hello world")

is same as

document.write("Hello world")

Window Object Properties

The following table lists the properties of the Window object:

Property Description
closed Indicates whether the current window is closed or not
console Returns a reference to the console object which provides access to the browser's debugging console (See Console object)
defaultStatus Sets or returns the status bar text for the given window
document Returns a reference to the document that the window contains (See Document object)
frameElement Returns the <iframe> element in which the current window is inserted
frames Returns all <iframe> elements in the current window
history Returns a reference to the history object associated with the window (See History object)
innerHeight Returns the height of the window's content area (viewport) including scrollbars
innerWidth Returns the width of a window's content area (viewport) including scrollbars
length Returns the number of <iframe> elements in the current window
localStorage Allows to save key/value pairs in a web browser. Stores the data with no expiration date
location Returns a reference to the location object associated with the window (See Location object)
name Sets or returns the name of a window
navigator Returns a reference to the navigator object associated with the window (See Navigator object)
opener Returns a reference to the window that created the window
outerHeight Returns the height of the browser window, including toolbars/scrollbars
outerWidth Returns the width of the browser window, including toolbars/scrollbars
pageXOffset Returns the number of pixels that the document has already been scrolled horizontally
pageYOffset Returns the number of pixels that the document has already been scrolled vertically
parent Returns the parent window of the current window
screen Returns a reference to the screen object associated with the window (See Screen object)
screenLeft Returns the horizontal coordinate of the window relative to the screen
screenTop Returns the vertical coordinate of the window relative to the screen
screenX An alias of screenLeft
screenY An alias of screenTop
scrollX An alias of pageXOffset
scrollY An alias of pageYOffset
sessionStorage Allows to save key/value pairs in a web browser. Stores the data for one session
self Returns an object reference to the window object itself
status Sets or returns the text in the statusbar of a window
top Returns a reference to the topmost window in the window hierarchy

Window Object Methods

The following table lists the methods of the Window object:

Method Description
alert() Displays an alert box with a message and an OK button
atob() Decodes a base-64 encoded string
blur() Removes focus from the current window
btoa() Encodes a string in base-64
clearInterval() Clears a timer set with setInterval()
clearTimeout() Clears a timer set with setTimeout()
close() Closes the current window
confirm() Displays a dialog with a message that the user needs to respond to
focus() Sets focus to the current window
getComputedStyle() Gets the current computed CSS styles applied to an element
getSelection() Returns a Selection object representing the range of text selected by the user
matchMedia() Returns a MediaQueryList object representing the specified media query string
moveBy() Moves a window relative to its current position
moveTo() Moves a window to the specified position
open() Opens a new browser window
print() Prints the content of the current window
prompt() Displays a dialog box that prompts the visitor for input
requestAnimationFrame() Requests the browser to call a function to update an animation before the next repaint
resizeBy() Resizes the window by the specified pixels
resizeTo() Resizes the window to the specified width and height
scroll() Deprecated. This method has been replaced by the scrollTo() method.
scrollBy() Scrolls the document by the specified number of pixels
scrollTo() Scrolls the document to the specified coordinates
setInterval() Calls a function or executes a code snippet at specified intervals (in milliseconds)
setTimeout() Calls a function or executes a code snippet after a specified number of milliseconds
stop() Stops the window from loading