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
alert(): Displays a dialog box with a warning message.
alert method
window.alert('Hello!'); // A warning message "Hello!" will appear.
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.
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.
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!").
Lessons in this chapter · How does JavaScript work in the browser?
- 1. How Do Browsers Work?
- 2. DOM (Document Object Model)
- 3. Browser Window Object
- 4. Window - window.screen
- 5. Window - window.location
- 6. Methods to Select HTML Elements - 1
- 7. How to Select HTML Elements - 2
- 8. Creating and Setting Attributes of HTML Elements
- 9. Events
- 10. Advanced Event Handling
- 11. Multiple-choice quiz
- 12. JSON(JavaScript Object Notation)
- 13. Promise
- 14. Async/Await Handling Asynchronous Processes
- 15. Cookies
- 16. Multiple-choice quiz
- 17. JavaScript Summary
Quiz
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