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
window
object: Thewindow
object is the top-level object in the BOM, and it represents the browser window. For example, you can use thewindow.innerHeight
andwindow.innerWidth
properties to get the dimensions of the browser window:
console.log(window.innerHeight);
console.log(window.innerWidth);
- The
document
object: Thedocument
object represents the current web page and allows you to access and manipulate its content. For example, you can use thedocument.getElementById
method to get an element by its id:
const header = document.getElementById("header");
header.innerHTML = "Hello, BOM";
- The
location
object: Thelocation
object represents the URL of the current web page and allows you to manipulate it. For example, you can use thelocation.href
property to get the current URL or thelocation.assign
method to navigate to a different page:
console.log(location.href);
location.assign("https://www.example.com");
- The
history
object: Thehistory
object provides access to the browsing history and allows you to manipulate it. For example, you can use thehistory.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