HTMLAnchorElement: host 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

HTMLAnchorElement 介面的 host 屬性是一個字串,包含主機。主機是由 hostname 組成,然後,如果 URL 的 不為空,則會有一個 ":",後面跟著 URL 的 port。如果 URL 沒有 hostname,此屬性將包含一個空字串 ""

有關詳細資訊,請參閱 URL.host

字串。

示例

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

anchor.href = "https://mdn.club.tw/en-US/HTMLAnchorElement";
anchor.host === "developer.mozilla.org";

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

anchor.href = "https://mdn.club.tw:4097/en-US/HTMLAnchorElement";
anchor.host === "developer.mozilla.org:4097";

規範

規範
HTML
# dom-hyperlink-host-dev

瀏覽器相容性

另見