How do you retrieve the full current page URL in JavaScript?
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" '
You must log in or register to comment.
