While the DOM provides access to the contents of a web page, the Browser Object Model (BOM) provides access to the surrounding web browser environment itself. The top-level root of the BOM is the window object.
window.location (URL & Navigation Control)Inspects and directs browser navigation:
// Reading URL information
console.log(window.location.href); // Full URL: "https://veewom.com/JavaScript/"
console.log(window.location.hostname); // "veewom.com"
console.log(window.location.pathname); // "/JavaScript/"
console.log(window.location.protocol); // "https:"
// Programmatic redirection
// window.location.href = "https://veewom.com/tutorials.htm";
// window.location.reload(); // Reloads current page
window.history (Session Navigation History)window.history.back(); // Equivalent to clicking browser Back button
window.history.forward(); // Equivalent to clicking browser Forward button
window.history.go(-2); // Jumps back 2 pages in history stack
window.navigator (Browser & Device Identity)console.log(navigator.userAgent); // Browser identity string
console.log(navigator.language); // User's default language (e.g. "en-US")
console.log(navigator.onLine); // Boolean: true if connected to internet
window.screen (Physical Screen Resolution)console.log("Device Screen Width:", window.screen.width);
console.log("Device Screen Height:", window.screen.height);
console.log("Available Screen Height:", window.screen.availHeight);
Exam Question: "What is the difference between innerWidth/innerHeight and outerWidth/outerHeight on window?"
window.innerWidth / innerHeight: The dimensions of the actual HTML viewport area displaying the web page (excluding browser toolbars and scrollbars).window.outerWidth / outerHeight: The entire physical size of the browser application window on the desktop monitor, including title bars, tabs, and window borders.How do you persist user preferences, shopping carts, and login tokens across browser sessions? Proceed to: JavaScript Web Storage: LocalStorage & Cookies →