要在JavaScript中获取当前页面的Internet主机端口号,请使用window.location.port属性。
您可以尝试运行以下代码来获取当前页面上的Internet主机端口数。浏览器将默认端口号设置为0或什至什么都没有-
<!DOCTYPE html>
<html>
   <body>
      <script>
         document.write("Port: " + window.location.port);
      </script>
   </body>
</html>