Lecture

Browser Window Object

The Window object represents a web browser's window or tab and is the top-level object in a web page that provides various features necessary for interacting with the web page.

The Window object signifies the web browser's window, encompassing several built-in objects, functions, and variables.

The document object, representing the document of a web page, is one of the attributes of the Window object.


Key Methods of the Window Object

  1. alert(): Displays a dialog box with a warning message.
alert method
window.alert('Hello!'); // A warning message "Hello!" will appear.

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

  1. setTimeout(): Executes a function after a specified amount of time.
setTimeout method
window.setTimeout(() => { alert('2 seconds have passed!'); }, 2000); // A warning message "2 seconds have passed!" will appear after 2 seconds.

  1. location: An object containing information and methods related to the current window's URL.
location object
console.log(window.location.href); // Outputs the URL of the current page.

Important Notes

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

Mission
0 / 1

Which is the most appropriate to fill in the blank?

The method to prompt the user to enter text is .
alert()
prompt()
setTimeout()
location

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

HTML
CSS
JavaScript
Loading...