Browser Object Model (BOM)
JavaScript access to browser-level functionality via window, location, navigator, screen and history.
JavaScript Browser Object Model (BOM)
- There is no official W3C standard for the BOM — modern browsers follow a de-facto standard.
- The BOM provides objects that expose the web browser's functionality.
- The most important BOM object is the
windowobject.
| Object | Purpose |
|---|---|
window | Represents the browser window; all global variables and functions are its properties. |
location | Current page URL; enables redirect and reload. |
navigator | Information about the user's browser and operating system. |
screen | Screen dimensions and colour depth. |
history | Navigate backward/forward through the user's browsing history. |
Common BOM Code Examples
// 1. Open a new browser window
window.open('https://example.com', 'blank');
// 2. Navigate to a different URL
window.location.href = 'https://example.com';
// 3. Display an alert dialog
window.alert('Hello from BOM!');
// 4. Get screen dimensions
var w = screen.width;
var h = screen.height;
// 5. Navigate browser history
history.back(); // go back
history.forward(); // go forward
// 6. Get browser information
var browser = navigator.userAgent;
Lecture 6 Summary
- The DOM is a W3C standard programming interface for HTML documents.
- The HTML DOM represents the page as a hierarchical tree of nodes.
- Node types: document, element, text, attribute and comment.
- Use
getElementById,getElementsByTagName,querySelectorAlland more to find elements. - Change content via
innerHTML; change styles viaelement.style.property. - Events respond to user actions —
onclick,onload,onsubmit,onchange. addEventListener()is the modern, recommended approach.- Validate forms on the client side before server submission.
- The BOM (
window,navigator,location,screen,history) gives access to browser-level functionality.
Activity — complete the code
Complete the code correctly to mark this lesson as complete automatically.
Complete the Browser Object Model examples.
// The most important BOM object//// Current page URLwindow..href = "https://example.com";// Browser informationvar browser = navigator.;// Screen dimensionsvar w = screen.;// Browsing historyhistory.(); // go back