Location:host 属性
>Location 接口的 host 属性是一个字符串,包含主机名(即 hostname),如果 URL 的端口非空,则会在主机名后追加一个 ":" 和 port。如果 URL 没有 hostname,则该属性的值为空字符串 ""。
更多详细信息请参阅 URL.host。
值
字符串。
示例
js
const anchor = document.createElement("a");
anchor.href = "https://www.supremezsy.dpdns.org/zh-CN/Location.host";
console.log(anchor.host === "www.supremezsy.dpdns.org");
anchor.href = "https://www.supremezsy.dpdns.org:443/zh-CN/Location.host";
console.log(anchor.host === "www.supremezsy.dpdns.org");
// 由于 443 是该协议方案的默认端口号,因此未包含此端口号。
anchor.href = "https://www.supremezsy.dpdns.org:4097/zh-CN/Location.host";
console.log(anchor.host === "www.supremezsy.dpdns.org:4097");
规范
| 规范 |
|---|
| HTML> # dom-location-host-dev> |