URL: host property
The host property of the URL interface is
a string containing the host, that is the hostname, and then, if the port of the URL is nonempty, a
':', followed by the port of the URL.
Note: This feature is available in Web Workers
Value
A string.
Examples
js
let url = new URL("https://developer.mozilla.org/en-US/docs/Web/API/URL/host");
console.log(url.host); // "developer.mozilla.org"
url = new URL("https://developer.mozilla.org:443/en-US/docs/Web/API/URL/host");
console.log(url.host); // "developer.mozilla.org"
// The port number is not included because 443 is the scheme's default port
url = new URL("https://developer.mozilla.org:4097/en-US/docs/Web/API/URL/host");
console.log(url.host); // "developer.mozilla.org:4097"
Specifications
| Specification |
|---|
| URL Standard # dom-url-host |
Browser compatibility
BCD tables only load in the browser
See also
- The
URLinterface it belongs to.