位置:port 屬性
Location 介面的 port 屬性是一個字串,其中包含 location URL 的埠號。如果埠是協議的預設埠(ws: 和 http: 為 80,wss: 和 https: 為 443,ftp: 為 21),則此屬性包含一個空字串,""。
可以設定此屬性來更改 URL 的埠。如果 URL 沒有 host 或者其 scheme 是 file:,則設定此屬性無效。它還會默默地忽略無效的埠號。
有關更多資訊,請參閱 URL.port。
值
字串。
示例
js
// Assume current page is at https://mdn.club.tw/en-US/docs/Location/port
const result = location.port; // Returns:''
js
// Assume another page is at https://mdn.club.tw:8888/en-US/docs/Location/port
const result = location.port; // Returns:'8888'
規範
| 規範 |
|---|
| HTML # dom-location-port-dev |
瀏覽器相容性
載入中…