Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14
Chapter 6

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 window object.
ObjectPurpose
windowRepresents the browser window; all global variables and functions are its properties.
locationCurrent page URL; enables redirect and reload.
navigatorInformation about the user's browser and operating system.
screenScreen dimensions and colour depth.
historyNavigate 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, querySelectorAll and more to find elements.
  • Change content via innerHTML; change styles via element.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 URL
window..href = "https://example.com";
 
// Browser information
var browser = navigator.;
 
// Screen dimensions
var w = screen.;
 
// Browsing history
history.(); // go back