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

CRUD Operations: The Foundation of Data Management

Every application that stores and manages data relies on a set of basic operations known…

3 days ago

Common PHP Mistakes Every Developer Should Avoid

PHP remains one of the most widely used server-side programming languages, powering platforms such as…

3 days ago

Danfo.js: The JavaScript Data Science Library

Danfo.js is an open-source JavaScript library designed for data manipulation, analysis, and machine learning. It provides…

4 days ago

Common Async/Await Mistakes Every JavaScript Developer Should Avoid

JavaScript's async and await keywords revolutionized asynchronous programming by making asynchronous code look and behave more like synchronous code.…

6 days ago

PGP Encryption And How It Works

Pretty Good Privacy (PGP) is one of the most widely used encryption systems for securing emails,…

1 week ago

How To Migrate from PostgreSQL to MySQL

Database migration is one of the most challenging tasks in software engineering. While both PostgreSQL…

2 weeks ago