You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Courses/IBM-JavaScript-Essentials/README.md
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1623,3 +1623,76 @@ You can change the order of elements within a parent container, which affects th
1623
1623
</script>
1624
1624
</body>
1625
1625
```
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
+
constbrowserName=navigator.appName;
1653
+
constbrowserVersion=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
+
constscreenWidth=screen.width;
1662
+
constscreenHeight=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
+
constcurrentURL=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.
0 commit comments