Browser Object Model
The BOM gives JavaScript access to the browser environment beyond the document — the current URL, navigation history, screen metrics, geolocation, clipboard, timers, and the global window object itself.
What is the BOM in JavaScript?
The Browser Object Model is everything the browser exposes outside the page content: window (the global object and viewport), location (the URL), history (back, forward and pushState), navigator (browser and device info, clipboard, geolocation) and screen. It's how you read or change the URL, open windows and detect capabilities.
location.href; // full URL
new URL(location.href).searchParams.get("q");
history.pushState({}, "", "/new-path"); // change URL without reload
window.innerWidth; // viewport width
await navigator.clipboard.writeText("copied!");
window.matchMedia("(prefers-color-scheme: dark)").matches;Key BOM Objects
windowwindow.innerWidth / innerHeightwindow.devicePixelRatiowindow.open(url, target)window.scrollTo(x, y)window.scrollBy(x, y)window.print()
locationlocation.href (full URL)location.pathnamelocation.search (?q=…)location.hash (#anchor)location.assign(url)location.replace(url)location.reload()
historyhistory.back()history.forward()history.go(n)history.pushState(state, title, url)history.replaceState(…)history.length
navigatornavigator.userAgentnavigator.languagenavigator.onLinenavigator.geolocationnavigator.clipboardnavigator.share(data)
screenscreen.width / heightscreen.availWidth / availHeightscreen.colorDepthscreen.pixelDepthscreen.orientation
TimerssetTimeout(fn, ms)clearTimeout(id)setInterval(fn, ms)clearInterval(id)requestAnimationFrame(fn)cancelAnimationFrame(id)
SPA Navigation with History API
pushState — add history entry
history.pushState({ page: 'home' }, '', '/home');
// URL changes, NO reload, user can go backreplaceState — no new entry
history.replaceState({ page: 'home' }, '', '/home');
// URL changes, replaces current, can NOT go backpopstate — handle back/forward
window.addEventListener('popstate', (e) => {
console.log('state:', e.state); // { page: 'home' }
renderPage(e.state?.page);
});URLSearchParams
const p = new URLSearchParams(location.search);
console.log(p.get('q')); // 'javascript'
p.set('sort', 'newest');
history.pushState(null, '', '?' + p);Common Pitfalls
Interactive BOM Explorer
Code Editor
<pre id="out"></pre>
<button id="push">pushState("?tab=2")</button>
<button id="copy">Copy URL</button>Preview
Browser Object Model — step by step
The window Object
The window object is the global object in a browser context. Every global variable and function you declare becomes a property of window. It also provides access to the entire BOM: location, history, navigator, screen, and timers.
🎯 Quick Check
Which API lets a single-page app update the URL in the address bar without triggering a full page reload?
The Browser Object Model: summary
Key points
windowis the global object in browsers;globalThisworks in every environment.- Use
URLandURLSearchParamsto read and build query strings safely. pushStateupdates the URL; listen topopstateto handle Back and Forward.- Feature-detect (
"clipboard" in navigator) instead of sniffing the user agent.
Frequently asked questions
›How do I get query parameters from the URL?
new URLSearchParams(location.search).get("name").