Get current page port number in JavaScript

Description

The following code shows how to get current page port number.

Example


<!--   www  . j  a  v  a 2  s . c  o m-->
<!DOCTYPE HTML>
<html>
<body>
<script>
document.writeln("port: " + document.location.port);
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get current page port number in JavaScript