URL:port 屬性
注意:此功能在 Web Workers 中可用。
URL 介面的 **port** 屬性是一個字串,其中包含 URL 的埠號。如果埠是協議的預設值(ws: 和 http: 為 80,wss: 和 https: 為 443,ftp: 為 21),則此屬性包含一個空字串,即 ""。
可以設定此屬性來更改 URL 的埠。如果 URL 沒有 host 或者其方案是 file:,則設定此屬性無效。它還會默默地忽略無效的埠號。
值
字串。
示例
js
// https protocol with non-default port number
new URL("https://example.com:5443/svn/Repos/").port; // '5443'
// http protocol with non-default port number
new URL("http://example.com:8080/svn/Repos/").port; // '8080'
// https protocol with default port number
new URL("https://example.com:443/svn/Repos/").port; // '' (empty string)
// http protocol with default port number
new URL("http://example.com:80/svn/Repos/").port; // '' (empty string)
// https protocol with no explicit port number
new URL("https://example.com/svn/Repos/").port; // '' (empty string)
// http protocol with no explicit port number
new URL("http://example.com/svn/Repos/").port; // '' (empty string)
// ftp protocol with non-default port number
new URL("ftp://example.com:221/svn/Repos/").port; // '221'
// ftp protocol with default port number
new URL("ftp://example.com:21/svn/Repos/").port; // '' (empty string)
規範
| 規範 |
|---|
| URL # dom-url-port |
瀏覽器相容性
載入中…
另見
- 它所屬的
URL介面。