본문으로 건너뛰기

Browser Window Object

Browser Window Object

The Window object, representing a web browser's window or tab, is the top-level object of a web page. It contains various properties and methods that provide necessary functionalities for interacting with the web page.

The Window object symbolizes the browser's window and includes numerous built-in objects, functions, and variables.

For example, the document object, which represents the document of the web page, is one of the properties of the Window object.

Metaphorically, the Window object is like the frame of a house. Various furniture and items inside the house can be considered similar to the various properties and methods within the Window object.


Key Methods and Properties

  1. alert(): Displays an alert dialog with a specified message.
window.alert('Hello!'); // An alert message "Hello!" will appear.

  1. prompt(): Displays a dialog box that prompts the user for input.
let name = window.prompt('Please enter your name.'); // The name entered by the user is stored in the variable name.

  1. setTimeout(): Executes a function after a specified time has elapsed.
window.setTimeout(() => {
alert('5 seconds have passed!');
}, 5000); // After 5 seconds, an alert message "5 seconds have passed!" will appear.

  1. location: An object that includes information and methods about the current window's URL.
console.log(window.location.href); // Prints the current page's URL.

Note

When using methods or properties of the Window object, in most cases, the window. prefix can be omitted. Hence, you can express it shortly, like alert("Hello!").

Becoming familiar with the various methods and properties offered by the Window object will greatly assist in web development, as it is vital for interacting with web pages!