JS MASTER CLASS /// BROWSER OBJECT MODEL /// REDIRECTS /// WINDOWS /// JS MASTER CLASS /// BROWSER OBJECT MODEL /// REDIRECTS /// WINDOWS /// JS MASTER CLASS /// BROWSER OBJECT MODEL /// REDIRECTS /// WINDOWS ///

JS Windows & Redirects

Master the BOM. Learn to control the browser window, read URLs, and programmatically redirect users using pure JavaScript.

redirects.js
1 / 12
12345
🌍

Tutor:Welcome to the Browser Object Model (BOM). While the DOM interacts with the document, the BOM interacts with the browser itself. The core of the BOM is the global 'window' object.


BOM Matrix

UNLOCK NODES BY MASTERING JS REDIRECTS.

Concept: The BOM

The Browser Object Model handles everything outside the document page. It allows JS to talk to the browser via the `window` object.

System Check

Which object is the root of the Browser Object Model?


Community Holo-Net

Showcase Your Routing Logic

ACTIVE

Built an advanced SPA router or clever redirect flow? Share your JavaScript solutions.

JavaScript Windows & Redirects

Author

Pascual Vila

Frontend Instructor // Code Syllabus

To understand redirects in JavaScript, you must first understand the BOM (Browser Object Model). While the DOM (Document Object Model) deals with the HTML contents of the page, the BOM allows JavaScript to "talk" to the browser itself.

The Window Object

The window object represents the browser's window. All global JavaScript objects, functions, and variables automatically become members of the window object. Even the Document Object Model (DOM) is a property of the window object.

Window Location

The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page. Since `window` is the global object, you can simply write `location` instead of `window.location`.

To redirect a user, you simply assign a new URL to the href property:
window.location.href = "https://www.example.com";

Replace vs Assign

By default, setting `location.href` behaves exactly like location.assign(). It loads the new document and saves the previous document in the browser's history, meaning the user can click the "Back" button to return.

However, if you want to redirect a user and prevent them from returning to the original page (e.g., redirecting away from a login screen after successful authentication), you should use location.replace(). This removes the current URL from the document history.

View Full Transcript+

This section covers the deep specifics of the window object, handling cross-origin issues, popup blockers intercepting window.open(), and modern approaches to routing (like React Router pushing to the History API without doing a hard window reload). A hard redirect via location.href triggers a full page refresh, which is often undesirable in Single Page Applications (SPAs).

Redirects Glossary

window

The global object representing the browser window containing a DOM document. All global variables are properties of this object.

snippet.js

location.href

Property that returns the entire URL of the current page, or allows you to redirect the page when assigned a new value.

snippet.js

location.replace()

Method that replaces the current resource with the one at the provided URL. The difference from assign() is that it does not save the page in session history.

snippet.js

location.assign()

Method that causes the window to load and display the document at the specified URL. Similar to setting location.href.

snippet.js

location.reload()

Method that reloads the current URL, like the Refresh button.

snippet.js

window.open()

Opens a new browser window or a new tab, depending on your browser settings and the parameter values.

snippet.js