In Javascript, browser objects are part of the Browser Object Model (BOM), which provides an interface for interacting with the browser.
Window Object: The window object provides access to various properties and methods that interact with the browser window and its environment.
Document Object: It represents the HTML Document, which contains the HTML document of the current window.
Navigator Object: It contains information about the current URL and can be used to navigate to other URLs.
History Object: it contains information about the browser's history and allows the manipulation of the browsing history.
Screen Object: It contains properties that detail the screen's size, color depth, and pixel density.
Manipulating the DOM: It helps us create, modify, or delete elements within the document object.
Responsive Design: Adjusting the layout based on window size properties.
Storage Management: with the help of Storage services such as `localStorage` and `sessionStorage` for storing data on the client side.
Handling Events: It handles event listeners on the window or document objects to respond to user interactions.
Geolocation Services: Get user's location using the `navigator.geolocation`.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Browser Objects Example</title> </head> <body> <script> // Accessing properties of the window object console.log("Window Width:", window.innerWidth); console.log("Window Height:", window.innerHeight); // Accessing properties of the navigator object console.log("User Agent:", navigator.userAgent); console.log("Preferred Language:", navigator.language); // Accessing properties of the history object console.log("History Object length:", history.length); // Accessing properties of the screen object console.log("Screen Width:", screen.width); console.log("Screen Height:", screen.height); </script> </body> </html>
// Accessing properties of the window object Window Width: 342 Window Height: 450 // Accessing properties of the navigator object User Agent: "Mozilla/5.0 (Macintosh;) AppleWebKit/595.1.10 (KHTML, like Gecko) Version/16.3.2 Safari/600.2.25" Preferred Language: "en-US" // Accessing properties of the history object History Object length: 3 // Accessing properties of the screen object Screen Width: 1440 Screen Height: 900