Loading
Browser Objects-tutorial
In JavaScript, BOM stands for Browser Object Model. The BOM is a set of built-in browser objects that allow developers to interact with and control the browser itself beyond just the HTML content.

With the BOM, you can

  • Open and close browser windows
  • Navigate to different URLs
  • Access browser history
  • Get screen and browser information
  • And much more



Example: Opening a new browser window

You can use the BOM to open a new browser window.


// Open a new window with Google
var newWindow = window.open("https://www.google.com", "Google", "width=800,height=600");



Key Objects and Features of the BOM


Window Object

  • Represents the entire browser window or tab.
  • Acts as the global object in the browser.
  • All BOM objects are children of the window object.
  • Example:
console.log(window.innerWidth); // Outputs the width of the browser window



Location Object

  • Contains information about the current page URL.
  • Allows navigation to other URLs.
  • Common properties:
              1. location.href – full URL
              2. location.hostname – domain name
              3. location.pathname – path after the domain

  • Example:
console.log(location.href); // Shows current page URL



History Object

  • Lets you interact with the browser’s session history.
  • You can navigate back and forth

history.back(); // Go to previous page
history.forward(); // Go to next page



Navigator Object

  • Provides information about the browser and the user's operating system.
  • Example:
console.log(navigator.userAgent); // Shows browser user agent string



Screen Object

  • Gives details about the user's screen (like width and height).
  • Example:
console.log(screen.width); // Screen width in pixels