window

Published May 29, 2023
Contribute to Docs

The window object is the global object of JavaScript when run within a browser and represents the browser window. All browsers support it. It contains as members all global JavaScript objects, functions, and variables. Such variables become properties of the window object, such functions become methods of the window object.

Note: If a browser window contains <iframe> tags, there will be one window object for the page containing the <iframe> tags, and an additional window object for the page in each <iframe>.

Syntax

Below shows the use of a window method, .alert(), to display a message to the user:

window.alert('Hello World!');

Because the window object is global, the “window.” portion can also be omitted:

alert('Hello World!');

The window object has a number of properties and methods, some of which are listed below:

window

clearInterval()
Cancels a timer previously established by setInterval().
clearTimeout()
Clears a previously scheduled timeout function.
confirm()
Instructs the browser window to show a optional message, the user then must confirm or cancel the message
prompt()
Displays a dialog with an optional message asking users to input some text.
setinterval()
Executes a function repeatedly at specified intervals.
setTimeout()
Allows users to execute callbacks after a period of time expressed in milliseconds.

All contributors

Looking to contribute?

Learn JavaScript on Codecademy