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:
- The
windowobject: Thewindowobject is the top-level object in the BOM, and it represents the browser window. For example, you can use thewindow.innerHeightandwindow.innerWidthproperties to get the dimensions of the browser window:
console.log(window.innerHeight);
console.log(window.innerWidth);
- The
documentobject: Thedocumentobject represents the current web page and allows you to access and manipulate its content. For example, you can use thedocument.getElementByIdmethod to get an element by its id:
const header = document.getElementById("header");
header.innerHTML = "Hello, BOM";
- The
locationobject: Thelocationobject represents the URL of the current web page and allows you to manipulate it. For example, you can use thelocation.hrefproperty to get the current URL or thelocation.assignmethod to navigate to a different page:
console.log(location.href);
location.assign("https://www.example.com");
- The
historyobject: Thehistoryobject provides access to the browsing history and allows you to manipulate it. For example, you can use thehistory.backmethod 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