--- title: URL.host slug: Web/API/URL/host translation_of: Web/API/URL/host ---
{{domxref("URL")}} 接口的 host
属性是一个 {{domxref("USVString")}} 值,包含了主机信息,也就是 主机名(hostname),还有,如果 URL 接口不为空,也会包含冒号 ':'
和 URL 的 端口(port)。
{{AvailableInWorkers}}
string = object.host;
object.host
= string;
{{domxref("USVString")}}.
var url = new URL('https://developer.mozilla.org/en-US/docs/Web/API/URL/host'); var result = url.host // "developer.mozilla.org" var url = new URL('https://developer.mozilla.org:443/en-US/docs/Web/API/URL/host'); var result = url.host // "developer.mozilla.org" // The port number is not included because 443 is the scheme's default port var url = new URL('https://developer.mozilla.org:4097/en-US/docs/Web/API/URL/host'); var result = url.host // "developer.mozilla.org:4097"
Specification | Status | Comment |
---|---|---|
{{SpecName('URL', '#dom-url-host', 'URL.host')}} | {{Spec2('URL')}} | 初始定义 |
{{Compat("api.URL.host")}}