xxxxxxxxxx
window.location.hash: "#2"
window.location.host: "localhost:4200"
window.location.hostname: "localhost"
window.location.href: "http://localhost:4200/landing?query=1#2"
window.location.origin: "http://localhost:4200"
window.location.pathname: "/landing"
window.location.port: "4200"
window.location.protocol: "http:"
window.location.search: "?query=1"
xxxxxxxxxx
window.location.pathname; // Returns path only (/path/example.html)
window.location.href; // Returns full URL (https://example.com/path/example.html)
window.location.origin; // Returns base URL (https://example.com)
xxxxxxxxxx
// Get url/path/baseUrl following.
window.location.pathname; // Returns path only (/path/example.html)
window.location.href; // Returns full URL (https://example.com/path/example.html)
window.location.origin; // Returns base URL (https://example.com)
xxxxxxxxxx
// Get the current URL
var currentUrl = window.location.href;
// Display the URL in the console
console.log(currentUrl);
xxxxxxxxxx
console.log(window.location.href);
As noted in the comments, the line below works, but it is bugged for Firefox.
document.URL
xxxxxxxxxx
// this gives you just the URL without params
var currentUrlWithoutParams = window.location.href.split("?")[0];