URL:port 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
备注: 此特性在 Web Worker 中可用。
URL
接口的 port
属性是一个表示 URL 端口号的字符串。
值
字符串。
示例
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; // ''(空字符串)
规范
Specification |
---|
URL # dom-url-port |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
port |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参见
- 所属的
URL
接口。