Location:host 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Location
接口的 host
属性是一个字符串,包含主机名(即 hostname
),如果 URL 的端口非空,则会在主机名后追加一个 ":"
和 port
。如果 URL 没有 hostname
,则该属性的值为空字符串 ""
。
更多详细信息请参阅 URL.host
。
值
字符串。
示例
js
const anchor = document.createElement("a");
anchor.href = "https://developer.mozilla.org/zh-CN/Location.host";
console.log(anchor.host === "developer.mozilla.org");
anchor.href = "https://developer.mozilla.org:443/zh-CN/Location.host";
console.log(anchor.host === "developer.mozilla.org");
// 由于 443 是该协议方案的默认端口号,因此未包含此端口号。
anchor.href = "https://developer.mozilla.org:4097/zh-CN/Location.host";
console.log(anchor.host === "developer.mozilla.org:4097");
规范
Specification |
---|
HTML # dom-location-host-dev |