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 port 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>
raja
Published on 26-Feb-2018 11:52:33
Advertisements