Example 1 — Basic Read
Beginner example for window.location.
console.log(typeof window.location.href);
console.log(window.location.protocol.length > 0); How It Works
- Step. href is the full address string.
- Step. protocol is like https:

window.location is the Location object for this window. location.href is the full URL. Assigning a new href navigates.
Read window.location with no parentheses.
window.location; | Call | What it does |
|---|---|
window.location | The Location object for this window’s URL. |
Window property in browsers. No import required.
| Parameter | Description |
|---|---|
| window.location | Read-only or assignable depending on the property. No function arguments. |
| Return Value | Description |
|---|---|
| * | The Location object for this window’s URL. |
Beginner example for window.location.
console.log(typeof window.location.href);
console.log(window.location.protocol.length > 0); Beginner example for window.location.
console.log(window.location === location);
console.log("hostname" in location); Beginner example for window.location.
console.log(location.pathname.length >= 1); window.location is a standard Window property in browsers.
Available in all modern browsers. Not used in plain Node.js without a DOM.
Bottom line: Safe in browsers. Skip in server-only Node scripts.
Continue through the Window properties list.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
9 people found this page helpful