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

10 Signs Your PC Has Been Hacked

Cybercriminals don't always announce their presence. Many compromises are designed to remain unnoticed for weeks…

1 week ago

What Killed jQuery?

For years, jQuery was everywhere. If you were building websites in the 2010s, there was a…

1 week ago

How to Resolve Git Merge Conflicts

Few things halt a developer’s flow faster than seeing the dreaded word: CONFLICT. A Git merge…

2 weeks ago

How to Create REST APIs in Java Spring Boot

Spring Boot is one of the most popular frameworks for building REST APIs in Java.…

2 weeks ago

Perks of Being a Copy-Paste Developer

Why borrowing code is a skill—when you understand what you're copying. For years, "copy-paste developer"…

4 weeks ago

Conditionally Disable an Input Field Using React Hook Form

Interactive forms rarely keep every field active all the time. Sometimes an input should only…

4 weeks ago