JavaScript BOM

JavaScript BOM (Browser Object Model)

The Browser Object Model (BOM) allows JavaScript to interact with the browser itself, not just the webpage.

Through BOM, JavaScript can:

✔ Control browser windows
✔ Access browser history
✔ Work with URL and location
✔ Detect browser information
✔ Access local/session storage


📌 window Object

The window object is the top-level object in the browser.
Everything in BOM is part of window.

Example:


🧱 Key BOM Components


🔹 1. window.alert() – Show Message Box


🔹 2. window.confirm() – Ask Yes/No Question

If user clicks:

  • ✔ OK → true

  • ❌ Cancel → false


🔹 3. window.prompt() – Input From User


🔹 4. window.open() and window.close()


🔹 5. window.setTimeout() — Delay Execution


🔹 6. window.setInterval() — Repeat Execution


🌐 Location Object

Used to work with the current URL.

Redirect to another page:


⏮ History Object

Used to navigate browser history.


📁 Navigator Object

Gives browser and device info.


💾 Storage (Web Storage)

Local Storage (saved permanently)

Session Storage (removed after tab closes)


🚀 Summary Table

BOM Feature Object Example
Alerts and dialogs window alert()
URL control location location.href
Browser history history history.back()
Browser info navigator navigator.userAgent
Data storage localStorage, sessionStorage .setItem()

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *