blob: f4ab84da3d1cbbb2cad8cc98e7ae3278d9628f7d (
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
|
---
title: 'Location: host'
slug: Web/API/Location/host
translation_of: Web/API/Location/host
---
<div>{{ApiRef("Location")}}</div>
<p>{{domxref("Location")}} 接口的 <strong><code>host</code></strong> 属性是包含了主机的一段 {{domxref("USVString")}},其中包含:主机名,如果 URL 的端口号是非空的,还会跟上一个 <code>':'</code> ,最后是 URL 的端口号。</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox notranslate"><em>string</em> = <em>object</em>.host;
<em>object.<code>host</code></em> = <em>string</em>;
</pre>
<h2 id="Examples">Examples</h2>
<pre class="brush: js notranslate">var anchor = document.createElement("a");
anchor.href = "https://developer.mozilla.org/en-US/Location.host"
anchor.host == "developer.mozilla.org"
anchor.href = "https://developer.mozilla.org:443/en-US/Location.host"
anchor.host == "developer.mozilla.org"
// 这里 <code>host </code>中没有包含端口号,因为 443 是 https协议的默认端口号
anchor.href = "https://developer.mozilla.org:4097/en-US/Location.host"
anchor.host == "developer.mozilla.org:4097"
</pre>
<h2 id="Specifications">Specifications</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('HTML WHATWG', '#dom-location-host', 'host')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.Location.host")}}</p>
|