window.location object of the
window object. The
window.location object contains information about the current URL, and it provides several properties and methods for accessing and manipulating the URL.
Here are some examples of how to use the
1. To get the entire URL, you can use the
let currentURL = window.location.href;
This will return the entire URL, including the protocol, domain, path, and query string.
2. To get just the domain, you can use the
let currentDomain = window.location.host;
This will return the domain of the URL, including the subdomain and top-level domain.
3. To get just the path, you can use the
let currentPath = window.location.pathname;
This will return the path of the URL, excluding the domain and query string.
4. To get the query string, you can use the
let currentQueryString = window.location.search;
This will return the query string of the URL, including the question mark.