Show List

Browser Object Model (BOM)

The Browser Object Model (BOM) is a part of the JavaScript programming language that provides access to the browser's window and its components, such as the document, location, history, and screen. The BOM allows JavaScript to interact with the user and the browser, making it possible to create dynamic web pages.

Here are some examples of how the BOM can be used in JavaScript:

  1. The window object: The window object is the top-level object in the BOM, and it represents the browser window. For example, you can use the window.innerHeight and window.innerWidth properties to get the dimensions of the browser window:
console.log(window.innerHeight);
console.log(window.innerWidth);
  1. The document object: The document object represents the current web page and allows you to access and manipulate its content. For example, you can use the document.getElementById method to get an element by its id:
const header = document.getElementById("header");
header.innerHTML = "Hello, BOM";
  1. The location object: The location object represents the URL of the current web page and allows you to manipulate it. For example, you can use the location.href property to get the current URL or the location.assign method to navigate to a different page:
console.log(location.href);
location.assign("https://www.example.com");
  1. The history object: The history object provides access to the browsing history and allows you to manipulate it. For example, you can use the history.back method to go back to the previous page:
history.back();
These are just a few examples of how the BOM can be used in JavaScript. The BOM provides a powerful tool for creating dynamic web pages and user interactions, and it is an essential part of the JavaScript language.

    Leave a Comment


  • captcha text