HTMLAreaElement: host 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

HTMLAreaElement 接口的 host 属性是一个字符串,包含主机名。它由 hostname 组成,如果 URL 的 端口非空,则后面跟着一个 ":",最后是 URL 的 port。如果 URL 没有 hostname,则该属性包含一个空字符串 ""

有关详细信息,请参阅 URL.host

字符串。

示例

js
const area = document.createElement("area");

area.href = "https://mdn.org.cn/en-US/HTMLAreaElement";
area.host === "developer.mozilla.org";

area.href = "https://mdn.org.cn:443/en-US/HTMLAreaElement";
area.host === "developer.mozilla.org";
// The port number is not included because 443 is the scheme's default port

area.href = "https://mdn.org.cn:4097/en-US/HTMLAreaElement";
area.host === "developer.mozilla.org:4097";

规范

规范
HTML
# dom-hyperlink-host-dev

浏览器兼容性

另见