To get the number of internet host port for the current page in JavaScript, use the window.location.port property.
Example
You can try to run the following code to get the number of Internet host ports on the current page. Browsers would how 0 or even nothing, for default port number −
<!DOCTYPE html> <html> <body> <script> document.write("Port: " + window.location.port); </script> </body> </html>