HTMLAnchorElement: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.

HTMLAnchorElement.host 属性是一个字符串,包含主机名,即 hostname,并且如果 URL 的端口号不为空,则后面会跟一个 ':' 和 URL 的端口号

一个字符串。

示例

js
const anchor = document.createElement("a");

anchor.href = "https://developer.mozilla.org/zh-CN/HTMLAnchorElement";
anchor.host === "developer.mozilla.org";

anchor.href = "https://developer.mozilla.org:443/zh-CN/HTMLAnchorElement";
anchor.host === "developer.mozilla.org";
// 不包含端口号,因为 443 是该方案的默认端口

anchor.href = "https://developer.mozilla.org:4097/zh-CN/HTMLAnchorElement";
anchor.host === "developer.mozilla.org:4097";

规范

Specification
HTML
# dom-hyperlink-host-dev

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
host

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见