位置:主機屬性
Location 介面的 host 屬性是一個字串,其中包含主機,即 hostname,如果 URL 的 埠 非空,則緊接著是一個 ":",然後是 URL 的 port。如果 URL 沒有 hostname,則此屬性包含一個空字串,""。
有關詳細資訊,請參閱 URL.host。
值
字串。
示例
js
const anchor = document.createElement("a");
anchor.href = "https://mdn.club.tw/en-US/Location.host";
console.log(anchor.host === "developer.mozilla.org");
anchor.href = "https://mdn.club.tw:443/en-US/Location.host";
console.log(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/Location.host";
console.log(anchor.host === "developer.mozilla.org:4097");
規範
| 規範 |
|---|
| HTML # dom-location-host-dev |
瀏覽器相容性
載入中…