HTMLAnchorElement: port 屬性

Baseline 已廣泛支援

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

HTMLAnchorElement 介面的 port 屬性是一個字串,其中包含 <a> 元素 href 的埠號。如果埠是協議的預設埠(ws:http:80wss:https:443ftp:21),則此屬性包含一個空字串 ""

可以設定此屬性來更改 URL 的埠。如果 URL 沒有 host 或其方案是 file:,則設定此屬性無效。它還會默默忽略無效的埠號。

有關更多資訊,請參閱 URL.port

字串。

示例

js
// An <a id="myAnchor" href="https://mdn.club.tw:443/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // returns ''
js
// Another <a id="myAnchor" href="https://mdn.club.tw:8888/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // Returns:'8888'

規範

規範
HTML
# dom-hyperlink-port-dev

瀏覽器相容性

另見