JavaScript Window - The Browser Object Model


The Browser Object Model (BOM) enables JavaScript to communicate with the browser.


The Browser Object Model (BOM)

No established rules exist for the Browser ObjectModel odel (BOM).

Modern web browsers use nearly identical methods and properties to enable JavaScript interactivity. These are commonly known as the methods and properties of the Browser Object Model (BOM).


The Window Object

All browsers support the window object, which represents the browser's window.

Every JavaScript object, function, and variable worldwide automatically becomes part of the window object.

Global variables are characteristics of the window object.

Functions that work globally are part of the window object.

The document object in the HTML DOM is actually a part of the window object.

window.document.getElementById("header");

is the same as:

document.getElementById("header");

Window Size

You can use two properties to figure out the dimensions of the browser window.

Both characteristics provide measurements in pixels.

  • The code window.innerHeight represents the vertical size of the browser window in pixels.
  • The code window.innerWidth represents the inner width of the browser window, measured in pixels.

The browser window, which is also called the browser viewport, does not take into account toolbars and scrollbars.


Other Window Methods

Some other methods:

  • window.open() creates a new window.
  • window.close() is used to close the current window.
  • window.moveTo() allows you to relocate the current window.
  • window.resizeTo() - changes the size of the open window.