The Browser's Control Panel: BOM

Discover the essential JavaScript objects that act as the bridge between your code and the user's browser.

Lesson ProgressStep 1 of 7
// The Browser...
0 EXP

Welcome! Let's explore the key objects that let JavaScript talk to the browser.

// The Browser Environment...

The `window` Object: The Global Stage

The `window` object is the top-level object in the browser environment. It represents the browser window or tab that your web page is loaded into.

Crucially, `window` is the global object. This means that any variables you declare in the global scope (outside of any function) automatically become properties of the `window` object. The same goes for functions.

var myVar = "Hello";
function sayHi() {
  console.log("Hi!");
}

console.log(window.myVar); // "Hello"
window.sayHi(); // "Hi!"

Key Properties & Methods

  • `window.document`: The entry point to the DOM (the page content).
  • `window.location`: Contains information about the current URL.
  • `window.history`: Provides access to the browser's session history.
  • `window.navigator`: Contains information about the browser (e.g., user agent).
  • `window.screen`: Contains information about the user's display.
  • `window.innerWidth` / `window.innerHeight`: The dimensions of the window's viewport.
  • `window.localStorage` / `window.sessionStorage`: APIs for storing data in the browser.
  • `window.alert(message)`: Displays a simple alert box.
  • `window.prompt(text)`: Displays a dialog box that prompts the user for input.
  • `window.setTimeout(func, ms)`: Executes a function after a specified delay.

Because `window` is global, you can (and usually do) omit it. For example, `alert("Hello")` is the same as `window.alert("Hello")`.

System Check

If you declare `var x = 10;` in the global scope, what is the most accurate way to access it?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🧭
BOM Explorer

Correctly identify the hierarchy and purpose of BOM objects.

🏗️
DOM Manipulator

Use the 'document' object to successfully change the page.

🚀
URL Master

Prove your mastery of 'location' and 'history' syntax.

Mission: Manipulate the Browser

Change the page title to "My BOM Project" using the `document` object. Then, add a comment on the next line showing how you would redirect to "google.com" using `location.href`.

A.D.A. Feedback:

> Awaiting input...

Challenge: Order the Hierarchy

A document's structure matters. Drag the elements into the correct hierarchical order, from the broadest context (top) to the most specific (bottom).

document (The Page)
window (The Browser)
document.body (An Element)

Challenge: Complete the Syntax

Fill in the missing parts to correctly redirect the browser to "google.com".

.. = "https://google.com";

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Browser Manipulator" project for feedback from other Net-Runners.

The Browser's Control Panel: A Deep Dive into the BOM

When you write JavaScript for the web, your code doesn't exist in a vacuum. It runs inside a specific environment: the browser. The Browser Object Model (BOM) is a collection of objects provided by the browser that allows your JavaScript to interact with that environment. It's the "control panel" that lets you manipulate the browser window, see information about the user's screen, and manage navigation.

BOM vs. DOM: The CriticalDifference

This is the most common point of confusion for beginners.

  • The BOM (Browser Object Model) refers to all objects that let you interact with the *browser itself*. This includes window, location, history, navigator, and screen.
  • The DOM (Document Object Model) refers to the structure of the *web page content*. It's represented by the document object.

The easiest way to remember it: The BOM is the house (the browser window). The DOM is the furniture inside the house (the HTML content). The document object is *part of* the window object. So, the DOM is a subset of the BOM.

Practical Uses for Each Core Object

1. `window` in Action

// Get window size
const width = window.innerWidth;

// Set a timer
setTimeout(() => {
  console.log("Time's up!");
}, 2000);

// Open a new tab
window.open("https://google.com");

Used for timers, opening new tabs, and accessing global properties.

2. `document` in Action

// Find an element by its ID
const title = document.getElementById("main-title");

// Change its text
title.textContent = "New Title!";

// Create a new element
const p = document.createElement("p");
p.textContent = "A new paragraph.";
document.body.appendChild(p);

The entry point for all DOM manipulation: finding, changing, and creating elements.

3. `location` in Action

// Get the current URL
const currentUrl = location.href;

// Get just the path
const path = location.pathname;

// Redirect to a new page
location.href = "https://new-page.com";

// Reload the current page
location.reload();

Used for reading URL components or redirecting the user.

4. `history` in Action

// Go back one page
history.back();

// Go forward one page
history.forward();

// Go back 2 pages
history.go(-2);

// Change URL without reload (SPA)
history.pushState(null, "", "/new-path");

Used for programmatic navigation and essential for Single Page Applications (SPAs).

Beyond these, the navigator object provides information about the browser itself (like navigator.userAgent) and the user's device (like navigator.geolocation). The screen object gives details about the user's display, such as screen.width.

Key Takeaway: Mastering the BOM is mastering the art of making a web page feel like a dynamic application. You use the DOM to change *what* the user sees, and the BOM to control *how* and *where* they see it.

BOM & DOM Glossary

BOM (Browser Object Model)
A collection of objects that provide an interface to the browser, independent of the web page content. It includes `window`, `location`, `history`, `navigator`, and `screen`.
DOM (Document Object Model)
A tree-like representation of the HTML document's structure. It's the API that allows you to read and manipulate the page's content, accessed via the `document` object.
`window`
The top-level object in the browser. It represents the browser window or tab and acts as the **global object**. All global variables and functions become properties of `window`.
`document`
A property of `window` that serves as the entry point to the DOM. You use it to find, create, and change HTML elements.
`document.getElementById(id)`
A method of the `document` object that returns the single element whose `id` matches the specified string.
`document.querySelector(selector)`
Returns the **first** element within the document that matches the specified CSS selector (e.g., `.my-class`, `#my-id`, `p`).
`location`
A property of `window` that contains information about the current page's URL. You can read properties like `location.href` (the full URL) or `location.pathname` (the path) or assign to `location.href` to redirect.
`history`
A property of `window` that provides an interface to the browser's session history. Allows you to move backward (`history.back()`), forward (`history.forward()`), or to a specific point (`history.go()`).
`history.pushState()`
A method that adds an entry to the browser's session history, allowing you to change the URL in the address bar without reloading the page. Crucial for Single Page Applications (SPAs).
`navigator`
A property of `window` that contains information about the browser application (e.g., `navigator.userAgent`) and device capabilities (e.g., `navigator.geolocation`).
`screen`
A property of `window` that contains information about the user's display, such as `screen.width` and `screen.height`.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching JavaScript and building robust, interactive web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest ECMAScript and Web API specifications and is periodically reviewed.

External Resources

Found an error or have a suggestion? Contact us!