Location portProperty
Location Object
Definition and Usage
The port property is a readable and writable string that can set or return the port portion of the current URL.
Note:If the port number is 80 (which is the default port number), it does not need to be specified.
Syntax
location.port
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the port property.
Example
Example
Return the port number of the current URL:
<script>
document.write(location.port);
</script>
document.write(location.port);
</script>
The output of the above example is:
Try it yourself »
Location Object Other Extensions