HTMLAnchorElement: host 屬性
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 |
瀏覽器相容性
載入中…
另見
- 它所屬的
HTMLAnchorElement介面。