Window location.port
Definition and Usage
The port
property sets or returns the port number of a URL.
Note
If the port number is not specified in the URL, or if it is a default port (80 for http) or (443 for https), most browsers will return an empty string.
See Also:
Syntax
Return the port property:
location.port
Set the port property:
location.port = port
Property Value
Parameter | Description |
port | The port number of the URL |
Return Value
Type | Description |
A string | The port number of a URL. If the port number is not specified or if it is a default port (like 80 or 443), most browsers will return an empty string. |
Browser Support
location.port
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |