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 Standard # dom-hyperlink-host-dev |
浏览器兼容性
BCD tables only load in the browser
参见
- 所属接口
HTMLAnchorElement
。