Introduction to JavaScript BOM
JavaScript may communicate directly with the browser environment, not simply the content of web pages, thanks to the Browser Object Model (BOM). The BOM handles the browser window, URL, history, screen size, and more, whereas the DOM concentrates on HTML elements.
Understanding the BOM helps you build smarter, more interactive web applications.
What Is JavaScript BOM?
The BOM (Browser Object Model) is a collection of objects provided by the browser that lets JavaScript communicate with the browser itself. The BOM is not standardized like the DOM, however the majority of contemporary browsers support the same essential items.
The main BOM object is:
All BOM objects exist inside the window object.
The Window Object
The window object represents the browser window or tab.
Common Uses:
Example
Location Object (URL Control)
The location object gives access to the current URL and allows redirection.
Common Uses:
Example
Redirect Page
History Object (Browser Navigation)
The history object allows navigation through the browser’s session history.
Common Methods
Example
Navigator Object (Browser Information)
The navigator object provides information about the user’s browser and device.
Common Properties
Example
Often used for feature detection, not browser detection.
Screen Object (User Screen Details)
The screen object provides information about the user’s display.
Common Properties
Example
Often used for feature detection, not browser detection.
Timers in BOM (setTimeout & setInterval)
JavaScript BOM provides timing functions.
setTimeout
Executes code once after a delay.
setInterval
Executes code repeatedly.
Common BOM Objects Comparison
Real-World Use Cases of BOM