window.location.href returns the href (URL) of the current page. window.location.hostname returns the domain name of the web host. window.location.pathname returns the path and filename of the current page.
Firstly, we'd need to extract the host from the given URL value. We can use the URI class: String urlString = "https://www.baeldung.com/java-tutorial"; URI uri = new URI(urlString); String host = uri. getHost();
Simply put, a domain name (or just "domain") is the name of a website. It's what comes after "@" in an email address, or after "www." in a web address. If someone asks how to find you online, what you tell them is usually your domain name.
If you are asking about the machine name of the host that served up the current page, you can find that with
window.location.hostname
If you are asking about the name of the machine that is displaying the page in a browser, that information is restricted by browsers for security purposes.
You can use document.domain
to get domain name.
window.location.host
EDIT: If you meant the domain of the client machine, I don't think it is possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With