softare development

JavaScript Browser Object Model (BOM)

The Browser Object Model (BOM) refers to all the JavaScript-accessible objects provided by the web browser (not the web page) that allow developers to interact with the browser itself — things like the window, the screen, the browser history, the location bar, and pop-ups.

Learn JavaScript from the comfort of your home

While the DOM is about the document (HTML), the BOM is about the browser environment.

BOM vs DOM (Quick Difference)

FeatureDOMBOM
What it RepresentsHTML documentBrowser environment
Provided byBrowserBrowser
Examplesdocument, elements, nodeswindow, navigator, location, history
PurposeManipulate page contentInteract with browser features

1. The window Object (The ROOT of BOM)

The window object is the global object for JavaScript running in the browser.

Everything in the BOM hangs from window.

Examples:

console.log(window.innerWidth);
console.log(window.innerHeight);

Common Window Methods

MethodDescription
alert()Displays popup alert
confirm()OK/Cancel popup
prompt()Input popup
setTimeout()Run function once after delay
setInterval()Run function repeatedly
clearTimeout()Stop timeout
clearInterval()Stop interval

Example:

setTimeout(() => {
  console.log("This runs after 3 seconds");
}, 3000);

2. window.location Object — URL Information & Navigation

Controls and retrieves parts of the current browser URL.

Common Properties

PropertyDescription
location.hrefFull URL
location.hostnameDomain
location.pathnamePage path
location.searchQuery string
location.hashFragment (#)
location.protocolhttp: / https:

Methods

MethodDescription
location.assign()Load a new page
location.replace()Replace current page (no back button)
location.reload()Refresh page

Example:

console.log(location.href);
location.reload();

3. window.history Object — Browser Navigation

Allows JavaScript to move forward/backward in the browsing history.

Methods

MethodDescription
history.back()Go to previous page
history.forward()Go to next page
history.go(n)Move n steps (-1, +1, etc.)

Example:

history.go(-1); // Equivalent to back()

4. window.screen Object — Device Screen Info

Provides information about the user’s screen.

Common Properties

PropertyDescription
screen.widthScreen width
screen.heightScreen height
screen.availWidthAvailable width
screen.availHeightAvailable height

Example:

console.log(screen.width, screen.height);

5. window.navigator Object — Browser & Device Metadata

Gives information about the browser and environment.

Useful Navigator Properties

PropertyDescription
navigator.userAgentBrowser/OS details
navigator.languageUser’s language
navigator.onLineOnline/offline status
navigator.geolocationGPS access (requires permission)

Example:

console.log(navigator.language);
console.log(navigator.onLine);

Geolocation Example

navigator.geolocation.getCurrentPosition(pos => {
  console.log(pos.coords.latitude, pos.coords.longitude);
});

6. Popup Control (open, close, moveTo, resizeTo)

Open a new popup window

let popup = window.open("https://example.com", "_blank", "width=500,height=500");

Close it

popup.close();

7. Timers — setTimeout & setInterval

Already part of window, but extremely important.

Example: Interval

let i = 0;
let timer = setInterval(() => {
  console.log("Tick: " + i++);
  if (i === 5) clearInterval(timer);
}, 1000);

8. Cookies via BOM

You can access cookies using:

document.cookie = "username=John; expires=Fri, 31 Dec 2025 23:59:59 GMT";
console.log(document.cookie);

Summary Table of BOM Objects

BOM ObjectPurpose
windowRoot of everything
locationURL navigation
historyForward/back navigation
screenScreen/device display info
navigatorBrowser/system info
alert/prompt/confirmPopup dialogs
setTimeout/setIntervalTimers

The BOM (Browser Object Model) is the set of JavaScript-accessible objects provided by the browser that let you interact with browser features such as navigation, history, screen, popups, timers, and browser metadata.

Recent Posts

Essential VS Code Extensions Every Developer Should Use

Visual Studio Code (VS Code) is powerful out of the box, but its real strength…

3 days ago

JavaScript Variables

1. What Is a Variable in JavaScript? A variable is a named container used to store data…

4 days ago

C++ Queue

1. What Is a Queue? A Queue is a linear data structure that follows the principle: FIFO – First…

5 days ago

Must-Know Angular Concepts

Angular is a full-featured frontend framework built by Google for creating large, maintainable, and high-performance web applications.…

7 days ago

Responsive Web Design (RWD)

What Is Responsive Web Design? Responsive Web Design (RWD) is an approach to building websites…

1 week ago

Geolocation API in JavaScript

The Geolocation API allows a web application to access a user’s geographical location (latitude, longitude, and more), with…

2 weeks ago