Skip to content

Commit eba477a

Browse files
committed
Browser Object Model
1 parent f53e2ff commit eba477a

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

Courses/IBM-JavaScript-Essentials/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,3 +1623,76 @@ You can change the order of elements within a parent container, which affects th
16231623
</script>
16241624
</body>
16251625
```
1626+
1627+
## Browser Object Model (BOM):
1628+
1629+
The browser Object model BOM in JavaScript, is a crucial aspect that provides a structured way to interact with the web browser. It allows you to control browser behavior, manipulate the browser window, and access client-specific information. the BOM deals with the browser's environment. Some of the key components of BOM are as follows, window, document, navigator, screen, history, and location.
1630+
1631+
- Window Object:
1632+
1633+
The Global Window object represents the browser window or tab, and serves as the root of the BOM. All Global JavaScript objects and functions are part of the window object. The window object encompasses various properties and methods. For instance,
1634+
1635+
1. window.alert(message) displays a simple alert dialog.
1636+
2. window.confirm(message) shows a confirmation dialog.
1637+
3. window.open(url, name, specs, replace) opens a new browser window or tab.
1638+
4. you can also close the current window with a window.close().
1639+
5. manipulate the current URL using the window.location
1640+
1641+
The window object extends its functionalities with features like
1642+
1643+
1. setTimeout, for delayed function execution.
1644+
2. storage options, such as localStorage, and sessionStorage for client-side data storage.
1645+
3. Additionally, window.history provides access to the browser session's history.
1646+
1647+
- Navigator Object:
1648+
1649+
The navigator object gives information about the client's browser, including the browser's name, version, and supported features.
1650+
1651+
```js
1652+
const browserName = navigator.appName;
1653+
const browserVersion = navigator.appVersion;
1654+
```
1655+
1656+
- Screen Object:
1657+
1658+
The screen object details the user's screen, including its dimensions and color depth.
1659+
1660+
```js
1661+
const screenWidth = screen.width;
1662+
const screenHeight = screen.height;
1663+
```
1664+
1665+
- History Object:
1666+
1667+
The history object represents the browser's session history, enabling navigation in the user's browsing history.
1668+
1669+
```js
1670+
history.back(); // navigates back one page
1671+
1672+
history.forward(); // navigate forward one page
1673+
```
1674+
1675+
- Location Objet:
1676+
1677+
The location object provides information about the current URL, and allows manipulation of the URL, facilitating redirection to other web pages.
1678+
1679+
```js
1680+
const currentURL = location.href;
1681+
location.href = "https://example.com";
1682+
```
1683+
1684+
- DOM vs BOM:
1685+
1686+
1. The DOM represents a web page's structure and content, offering a hierarchical, easy access and manipulation model. Meanwhile, the BOM provides access to browser specific features, settings, and behaviors, enabling control over windows, navigation, and user interactions.
1687+
1688+
2. The DOM consists of a tree-like structure of HTML elements, attributes, and text nodes, representing the web page's content, accessible through the document object. The BOM includes various objects and features like a window, navigator, screen, history, and location, providing access to browser-specific information and functionalities.
1689+
1690+
3. The DOM allows dynamic manipulation of HTML elements, including text, attributes, styles, and structure. Meanwhile, the BOM goes beyond content, empowering control over browser features like alerts, windows, history, and client information.
1691+
1692+
4. DOM is organized hierarchically and represents HTML elements, attributes, and text nodes as notes, forming a structured layout. In contrast, the BOM lacks a hierarchical structure with loosely related objects offering independent access.
1693+
1694+
5. Accessing the DOM involves interacting through the document object, like using document.getElementById Element ID. For the BOM, direct interaction with objects occurs through the window object, for example, window.alert etc.
1695+
1696+
6. DOM usage includes modifying text content, adding or removing HTML elements, updating attributes, changing styles, and handling events within the web page. BOM usage includes opening new browser windows or tabs, controlling browser history, displaying alerts, managing client information, and handling browser-specific tasks.
1697+
1698+
##

0 commit comments

Comments
 (0)