How do you retrieve the full current page URL in JavaScript? | A1Lab@FahadM to JavaScriptEnglish •
edit-2
12 days ago

How do you retrieve the full current page URL in JavaScript?

message-square
0

Access **window.location.href`** to retrieve the complete current URL (including protocol, domain, path, query string, and hash fragment).

Retrieve Full URL & Individual Parts

// Full URL (e.g., "[https://forum.a1lab.tech/post/1?sort=top#comments](https://forum.a1lab.tech/post/1?sort=top#comments)")
const fullUrl = window.location.href;

// Useful URL components
console.log(window.location.origin);   // "[https://forum.a1lab.tech](https://forum.a1lab.tech)"
console.log(window.location.pathname); // "/post/1"
console.log(window.location.search);   // "?sort=top"
console.log(window.location.hash);     // "#comments" '