The port property represents the port portion of the URL. This normally follows the hostname, but is not always available.
http://www.java2s.com:8080/index.htm, the port is equal to 8080.
<html>
<head>
<title> Using the port property of the Location object</title>
</head>
<body>
<script language="JavaScript">
<!--
function show(){
alert(document.location.port);
}
-->
</script>
<form name="form1">
Click the button to get the current location.port value of the following address:
<br>
http://www.java2s.com
<br>
<input type="button" name="getport" value="Get port" onClick='show()'>
<br>
</form>
</body>
</html>