The port
property of the URL
interface is a string containing the port number of the URL.
Note: If an input string passed to the URL()
constructor doesn't contain an explicit port number (e.g., https://localhost
) or contains a port number that's the default port number corresponding to the protocol part of the input string (e.g., https://localhost:443
), then in the URL
object the constructor returns, the value of the port property will be the empty string: ''
.
Value
Examples
new URL("https://example.com:5443/svn/Repos/").port;
new URL("http://example.com:8080/svn/Repos/").port;
new URL("https://example.com:443/svn/Repos/").port;
new URL("http://example.com:80/svn/Repos/").port;
new URL("https://example.com/svn/Repos/").port;
new URL("https://example.com/svn/Repos/").port;
new URL("ftp://example.com:221/svn/Repos/").port;
new URL("ftp://example.com:21/svn/Repos/").port;
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
port |
32 |
13 |
22 |
No |
19 |
10 |
4.4.3 |
32 |
22 |
19 |
10 |
2.0 |
See also
- The
URL
interface it belongs to.