Advance JavaScript (DOM, BOM, Web API) / Browser Object Model (BOM)

Introduction to the BOM

πŸ“Œ What is BOM?

BOM (Browser Object Model) allows JavaScript to interact with the browser itself, not just the web page.

It provides objects to control:

  • Browser window

  • URL

  • History

  • Screen

  • User actions (alerts, navigation, etc.)


πŸ“¦ Main BOM Objects

  1. window

    • The top-level object of the browser

    • All BOM objects are part of window

    window.alert("Hello!");
  2. location

    • Used to get or change the current URL

    console.log(location.href);
    location.reload();
  3. history

    • Manages browser navigation (back/forward)

    history.back();
    history.forward();
  4. navigator

    • Provides browser and device information

    console.log(navigator.userAgent);
  5. screen

    • Gives screen size information

    console.log(screen.width, screen.height);

πŸ†š BOM vs DOM

BOM

DOM

Controls browser

Controls HTML document

Deals with window, URL, history

Deals with elements, tags

Browser-related

Page-related


⭐ Key Point

  • BOM is not standardized like DOM

  • Supported by all modern browsers

  • Used for navigation, alerts, and browser control