值
字符串。
示例
js
// 使用非默认端口号的 https 协议
new URL("https://example.com:5443/svn/Repos/").port; // '5443'
// 使用非默认端口号的 http 协议
new URL("http://example.com:8080/svn/Repos/").port; // '8080'
// 使用默认端口号的 https 协议
new URL("https://example.com:443/svn/Repos/").port; // ''(空字符串)
// 使用默认端口号的 http 协议
new URL("http://example.com:80/svn/Repos/").port; // ''(空字符串)
// 没有明确端口号的 https 协议
new URL("https://example.com/svn/Repos/").port; // ''(空字符串)
// 没有明确端口号的 http 协议
new URL("https://example.com/svn/Repos/").port; // ''(空字符串)
// 使用非默认端口号的 ftp 协议
new URL("ftp://example.com:221/svn/Repos/").port; // '221'
// 使用默认端口号的 ftp 协议
new URL("ftp://example.com:21/svn/Repos/").port; // ''(空字符串)
规范
| 规范 |
|---|
| URL> # dom-url-port> |
浏览器兼容性
参见
- 所属的
URL接口。