Example
Return the port number of the current URL:
var x = "Port: " + location.port;
The result of x will be (If the port number is 80, which is default, nothing will be returned):
Try it Yourself »
Definition and Usage
The port property sets or returns the port number the server uses for a URL.
Note: If the port number is not specified in the URL (or if it is the scheme's default port - like 80, or 443), some browsers will display 0 or nothing.
Browser Support
Property | |||||
---|---|---|---|---|---|
port | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the port property:
location.port
Set the port property:
location.port=port
Property Values
Value | Type | Description |
---|---|---|
port | String | Specifies the port number of the URL |
Technical Details
Return Value: | A String, representing the port number of a URL. Note: If the port number is not specified or if it is the scheme's default port (like 80 or 443), an empty string is returned |
---|
< Location Object