JavaScript - BOM Overview (Window, Navigator, Location)
Overview
Estimated time: 15–20 minutes
The Browser Object Model (BOM) provides access to browser features outside the DOM, such as the window, navigator, and location objects.
Learning Objectives
- Access and use the
window
,navigator
, andlocation
objects. - Understand the role of BOM in web APIs.
Prerequisites
window Object
console.log(window.innerWidth, window.innerHeight);
window.alert('Hello!');
navigator Object
console.log(navigator.userAgent);
console.log(navigator.language);
location Object
console.log(location.href);
location.reload();
Common Pitfalls
- Some BOM features are not available in all browsers or environments (e.g., Node.js).
Summary
The BOM provides access to browser-level features and is essential for interacting with the user's environment.