aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/url/host/index.html
blob: 4db9e53887eb5f74440ecc0f5f9c4a7e3e47cbd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
title: URL.host
slug: Web/API/URL/host
translation_of: Web/API/URL/host
---
<div>{{ApiRef("URL API")}}</div>

<p>{{domxref("URL")}} 接口的 <strong><code>host</code></strong> 属性是一个 {{domxref("USVString")}} 值,包含了主机信息,也就是 <em>主机名(hostname)</em>,还有,如果 URL 接口不为空,也会包含冒号 <code>':'</code> 和 URL 的 <em>端口(port)</em></p>

<p>{{AvailableInWorkers}}</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>string</em> = <em>object</em>.host;
<em>object.<code>host</code></em> = <em>string</em>;
</pre>

<p> </p>

<h3 id="返回值">返回值</h3>

<p>{{domxref("USVString")}}.</p>

<p> </p>

<h2 id="示例">示例</h2>

<pre class="brush: js">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"
</pre>

<h2 id="详情">详情</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('URL', '#dom-url-host', 'URL.host')}}</td>
   <td>{{Spec2('URL')}}</td>
   <td>初始定义</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容">浏览器兼容</h2>

<div class="hidden">本页面的兼容性表格是由结构化数据生成的。如果你愿意为这些数据做点贡献,请在 github <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 检出代码,然后发送 pull request 给我们。</div>

<p>{{Compat("api.URL.host")}}</p>

<h2 id="参考">参考</h2>

<ul>
 <li>所属的 {{domxref("URL")}} 接口。</li>
</ul>