# How to get the number of the internet host port for the current page in JavaScript?

JavascriptWeb DevelopmentFront End Scripts

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>
Updated on 23-Jun-2020 08:04:48