The Wayback Machine - https://web.archive.org/web/20240603042933/https://www.geeksforgeeks.org/browser-object-model/
Open In App

Browser Object Model

Last Updated : 22 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Browser Object Model (BOM) is a programming interface JavaScript tool for working with web browsers. This enables access & manipulation of the browser window, frames, and other browser-related objects by facilitating the JavaScript code.

The main object is “window,” which helps to interact with the browser. By default, you can call window functions directly.

window.alert(" Hey Geeks"); 
// Same as
alert(" Hey Geeks ");  

Note: It is not recommended always to explicitly mention “window” because it’s the default. So, the alert(” Hey Geeks “); is equivalent to the longer version.

Browser Object Model Types

Types

Description

Window Object Model Represents the browser window and serves as the main tool for interaction within the Browser Object Model (BOM).
History Object Model Enables navigation control by keeping track of the user’s browsing history in the Browser Object Model (BOM).
Screen Object Model Offers information about the user’s screen, like its size, within the Browser Object Model (BOM).
Navigator Object Model Provides details about the user’s browser and system characteristics within the Browser Object Model (BOM).
Location Object Model Manages the current web address (URL) and allows changes within the Browser Object Model (BOM).

Window Object

The ‘window object in JavaScript represents your web browser’s window. Everything you create in JavaScript, like variables and functions, is automatically part of this window.

Global variables are like items in the window, and global functions are tools you can use from anywhere. The “document” object, which deals with HTML content, is also a special tool in the window. So, think of the “window” as a big container holding all your JavaScript stuff.

The HTML DOM Objects can be treated as the window object’s property

window.document.getElementById("header");

which is the same as

document.getElementById("header");

Window Size

You can use two properties to find out the dimensions of the browser window, and both provide the measurements in pixels:

Window Size

Description

window.innerHeight This gives you the vertical size or height of the browser window in pixels.
window.innerWidth This gives you the horizontal size or width of the browser window in pixels.

Other Window Methods

Window Methods Descriptions
window.open() This method is used to open a new tab or window with the specified URL and name.
window.close() This method is used for closing a certain window or tab of the browser that was previously opened by the window.open( ) method.
window.moveTo() This method is used in the window to move the window from the left and top coordinates.
window.resizeTo() This method is used to resize a window to the specified width and height

Example: Implementation to show current window size.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
  
    <h1>GeeksforGeeks</h1>
    <p id="geeks"></p>
    <script>
        document.getElementById("geeks").innerHTML =
            "Browser inner window width: "
             + window.innerWidth + "px<br>" +
            "Browser inner window height: " 
             + window.innerHeight + "px";
    </script>
</body>
  
</html>


Output:

Screenshot-2024-01-19-161049

 Advantages & Disadvantages of BOM

Advantages

  • User Interaction: BOM allows websites to show alerts, prompts, and confirmations, making them more interactive.
  • Navigation Control: It also helps to manage going back or forward in your browsing history using tools like ‘history.’
  • Browser Details: BOM gives information about your browser through the ‘navigator’ tool, helping to adjust content for different browsers and systems.
  • Location Management: Using the ‘location’ tool, BOM lets websites change web addresses for dynamic content and easy redirection.

Disadvantages

  • Browser Compatibility: It may work differently in various browsers, causing compatibility issues.
  • Security Concerns: Some BOM features, like pop-ups, can be exploited for security risks.
  • Client-Side Dependency: It relies heavily on the client side, hence affecting performance.
  • Limited Standardization: It lacks a standardized specification, leading to variations in implementation.


Similar Reads

What is BOM( Browser Object Model) ?
The Browser Object Model (BOM) is a fundamental component of web development. It includes a collection of objects and methods that enable interaction with the browser window. Unlike the Document Object Model (DOM), which focuses on page structure, the BOM enables manipulation of the browser. Central to the BOM is the window object which is a global
1 min read
What is the role of the Navigator Object in JavaScript for Handling Browser Related Information ?
Think of it as your navigator in the online world – it provides information about the browser environment your script is running in. The navigator object is part of the window object and contains properties that give you details about the user's browser. Here are a couple of things the navigator object can tell you: Browser Information: This line o
1 min read
Mongoose Document Model.prototype.model() API
The Mongoose Document API Model.prototype.model() method of the Mongoose API is used on the Document model. It allows to get the model instance. We can call this method on any model object and by providing another model name to the method parameter we will get the new instance of that model. Let us understand the model() method using an example. Sy
3 min read
Introduction to Model View View Model (MVVM)
Description of Model is as follows: MODEL: ( Reusable Code – DATA ) Business Objects that encapsulate data and behavior of application domain, Simply hold the data. VIEW: ( Platform Specific Code - USER INTERFACE ) What the user sees, The Formatted data. VIEWMODEL: ( Reusable Code – LOGIC ) Link between Model and View OR It Retrieves data from Mode
3 min read
Difference between id and cid properties on a model object in Backbone.js
Backbone.js is a compact library used to organize JavaScript code. An MVC/MV* framework is another term for it. If MVC is unfamiliar to you, it is merely a technique for designing user interfaces. The creation of a program's user interface is made considerably easier by JavaScript functions. BackboneJS provides a variety of building elements to aid
3 min read
Page Object Model (POM)
What is POM? POM is a design pattern which is commonly used in Selenium for Automating the Test Cases. This design pattern can be used with any kind of framework like keyword-driven, Data-driven, hybrid framework, etc. The Page object is an object-oriented class which acts as an interface for the page of your Application under test. Page class cont
3 min read
EmberJS Object Model
An object model refers to the way objects are structured and organized within the framework. Ember.js is an open-source JavaScript framework for building web applications, and it follows the Model-View-Controller (MVC) architectural pattern. In Ember.js, the item model rotates around models, which address the fundamental information of your applica
2 min read
What is the DOM (Document Object Model) ?
The DOM, or Document Object Model, is a programming interface for web documents. It represents the structure of a document as a tree of objects, where each object corresponds to a part of the document, such as elements, attributes, and text. The DOM provides a way for programs to manipulate the structure, style, and content of web documents dynamic
2 min read
HTML DOM (Document Object Model)
HTML DOM (Document Object Model) is a hierarchical representation of HTML documents. It defines the structure and properties of elements on a webpage, enabling JavaScript to dynamically access, manipulate, and update content, enhancing interactivity and functionality. Note: It is called a Logical structure because DOM doesn't specify any relationsh
9 min read
How will you access the reference to same object within the object in PHP ?
In this article, we will see how we can access the reference to the same object within that object in PHP. To do that we have to use the "$this" keyword provided by PHP. PHP $this Keyword: It is used to refer to the current objectIt can only be used inside the internal methods of the class.$this keyword can refer to another object only if it is ins
2 min read