Computers & ProgrammingFrontend DevelopmentJavaScript

JavaScript Window Object

The JavaScript Window object represents an open window in a browser. While there is no standard that applies to the Window object, all major browsers support it so it is safe to use in your web projects. There are many useful properties and methods that can be used in your JavaScript projects.

Window Object Properties

PropertyDescription
closedGets a Boolean value indicating whether a window has been closed or not.
defaultStatusSets or returns the default text in the status bar of a window. Only Opera.
documentGets the Document object for the window.
framesGets an array of all the frames in the current window.
historyGets the History object for the window.
innerHeightSets or gets the inner height of a window’s content area.
innerWidthSets or gets the inner width of a window’s content area.
lengthGets the number of frames in a window.
locationGets the Location object for the window.
nameSets or gets the name of a window.
navigatorGets the Navigator object for the window.
openerGets a reference to the window that created the window.
outerHeightSets or gets the outer height of a window, including toolbars and scrollbars.
outerWidthSets or gets the outer width of a window, including toolbars and scrollbars
pageXOffsetGets the pixels the current document has been scrolled horizontally from the upper left corner. No IE.
pageYOffsetGets the pixels the current document has been scrolled vertically from the upper left corner. No IE.
parentGets the parent window of the current window.
screenGets the Screen object for the window.
screenLeftGets the x coordinate of the window relative to the screen. No Firefox.
screenTopGets the y coordinate of the window relative to the screen. No Firefox.
screenXGets the x coordinate of the window relative to the screen. No IE.
screenYGets the y coordinate of the window relative to the screen. No IE.
selfGets the current window.
statusSets the text in the status bar of a window. Only Opera.
topGets the top most browser window.

Window Object Methods

MethodDescription
alert()Displays an alert with a message and an OK button.
blur()Removes focus from the current window. No Opera. No Chrome.
clearInterval()Clears a timer set with setInterval().
clearTimeout()Clears a timer set with setTimeout().
close()Closes the current window.
confirm()Displays a dialog box with a message and an OK and a Cancel button.
createPopup()Creates a pop-up window. IE only.
focus()Sets focus to the current window.
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.
resizeBy()Resizes the window by the specified pixels. No Opera. No Chrome.
resizeTo()Resizes the window to the specified width and height.
scrollBy()Scrolls the content by the specified number of pixels.
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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top