翻译正在进行中。

URL 接口的 host 属性是一个 USVString 值,包含了主机信息,也就是 主机名(hostname),还有,如果 URL 接口不为空,也会包含冒号 ':' 和 URL 的 端口(port)

Note: 此特性在 Web Worker 中可用。

语法

string = object.host;
object.host = string;

 

返回值

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
URL
URL.host
Living Standard 初始定义

浏览器兼容

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
hostChrome Full support YesEdge Full support 13Firefox Full support 22IE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

参考

  • 所属的 URL 接口。

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, Mukti
最后编辑者: mdnwebdocs-bot,